• JSP(5):接受参数 【原创】


    接受传递过来的参数:request.getParameter("参数名称")。此方法返回String类型。

    需要将String类型转换为int类型:int 变量名称 = Interger.parseInt("包含数字的字符串")。

    GET方式提交表单,地址栏会显示。POST方式,则地址栏不会显示参数。

    例:提交表单

    <html>
    <head>
    <title>JSP</title>
    </head>
    <body>
    <!-- HTML与服务器交互的主要途径是表单 -->
    输入表格的行数与列数,进行表格打印操作
    <form action="printTable03.jsp" method="get">
    行数:<input type="text" name="rownum"><br>
    列数:<input type="text" name="colnum"><br>
    <input type="submit" value="打印">
    </form>
    </body>

    ---------------------------------------------------------

    接收参数并输出:

    <html>
    <head>
    <title>JSP</title>
    </head>
    <body>
    <%
    // 接收参数
    String t_row = request.getParameter("rownum") ;
    String t_col = request.getParameter("colnum") ;

    // 将字符串变为整数
    int row = 0 ;
    int col = 0 ;
    try
    {
       row = Integer.parseInt(t_row) ;
       col = Integer.parseInt(t_col) ;
    }
    catch(Exception e)
    {
    %>
       Input Error!!!
    <%
    }
    %>
    <table border="1">
    <%
    // 打印9×9的表格
    for(int i=0;i<row;i++)
    {
    %>
       <tr>
    <%
       for(int j=0;j<col;j++)
       {
    %>
        <td><%=i*j%></td>
    <%
       }
    %>
       </tr>
    <%
    }
    %>
    </table>
    </body>
    </html>
    </html>

  • 相关阅读:
    NOJ-1581 筷子 (线性DP)
    UVA-242 Stamps and Envelope Size (DP)
    POJ 1860 (SPFA判断正环)
    POJ 3268 最短路水题
    STL----priority_queue
    STL----unique
    POJ 2031(最小生成树Kruskal算法+几何判断)
    POJ 3468(线段树区间修改+区间求和)
    学习线段树
    POJ 1251(最小生成树裸题)
  • 原文地址:https://www.cnblogs.com/yony/p/2569549.html
Copyright © 2020-2023  润新知