zoukankan      html  css  js  c++  java
  • 内置对象—request

    1.request:处理客户端浏览器提交的请求中的各项参数和选项。form表单提交后处理中文乱码问题的方法:在处理表单的页面写request.setCharacterEncoding("gb2312");

    request.setAttribute(key,obj);此种方法传值时只有当用forward跳转时才能传值!!在servlet中用

      request.setAttribute("noticeList", noticeList);  request.getRequestDispatcher("Notice.jsp").forward(request, response);  也是forward跳转。

    request取数组的值,例如在login.jsp页面内:

    <%@ page contentType="text/html;charset=gbk"  %> <html> <body>

     <form action="login_deal.jsp" method="post">  <table align="center">

     <tr><th>姓名:</th><td><input type="text" name="name"></td></tr>

     <tr><td><input type="checkbox" name="like" value="鹿晗"/>鹿晗</td></tr>

     <tr><td><input type="checkbox" name="like" value="吴亦凡"/>吴亦凡</td></tr>

     <tr><td><input type="checkbox" name="like" value="黄子韬"/>黄子韬</td></tr>  

    <tr><td><input type="checkbox" name="like" value="金钟大"/>金钟大</td></tr>

     <tr><th>密码:</th><td><input type="password" name="pwd"></td></tr>

     <tr><td><input type="submit" value="提交"/></td></tr>  </table>

       </form> </body> </html>

    在接收表单值的页面login_deal.jsp页面中的代码:

    <%@ page contentType="text/html; charset=gb2312" %>
    <%@page import="java.lang.reflect.Array"%>
    <html><body>
    <%
     request.setCharacterEncoding("gb2312");
     %>
     <table>
    <tr><td>用户名:</td><td><%=request.getParameter("name") %></td></tr>
    <%
     String[] likes=request.getParameterValues("like");
     if(likes!=null){
      int size=0;
      size=Array.getLength(likes);
      for(int i=0;i<size;i++){%>
      
      <tr><td><%=likes[i] %></td></tr>
      
      <%
      }
     }
     %>
    <tr><td>密码:</td><td><%=request.getParameter("pwd") %></td></tr>
    </table>
    </body></html>


       

  • 相关阅读:
    [网络流24题(1/24)] 最小路径覆盖问题(洛谷P2764)
    Codeforces 1082 G(最大权闭合子图)
    bzoj 1497(最大权闭合图/最小割)
    loj 515(bitset优化dp)
    bzoj 3998 (后缀自动机)
    HDU 6071(同余最短路)
    SPOJ COT2 (树上莫队)
    Atcoder Grand Contest 20 C(bitset优化背包)
    hdu 6480-6489 (2018 黑龙江省大学生程序设计竞赛)
    POJ 2594 Treasure Exploration(可重点最小路径覆盖)
  • 原文地址:https://www.cnblogs.com/mymindview/p/3505149.html
Copyright © 2011-2022 走看看