页面与页面之间传递参数

方式一:

<jsp:useBean id="userForm" class="com.wgh.UserForm" scope="page"/>在这个类里面set get
<jsp:setProperty name="userForm" property="*"/>

输入框<input name="pwd" type="password" id="pwd"></td>要有类的一致

${userForm.pwd} 取得属性

方式二:

<form name="form1" method="post" action="PollServlet">
在配置文件里面

<servlet>
    <servlet-name>PollServlet</servlet-name>
    <servlet-class>com.wgh.servlet.PollServlet</servlet-class>
  </servlet>

  <servlet-mapping>
    <servlet-name>PollServlet</servlet-name>
    <url-pattern>/PollServlet</url-pattern>
  </servlet-mapping>

类里面用map元素

 String[] arr={"基础教程类","实例集锦类","经验技巧类","速查手册类","案例剖析类"};
   map=new HashMap();
   for(int i=0;i<arr.length;i++){
    if(item.equals(arr[i])){ //判断是否为选定的投票项
     map.put(arr[i], 1);
    }else{
     map.put(arr[i], 0);
    }

out.println("<script>alert('投票成功!');window.location.href='showResult.jsp';</script>"); //投票完之后来到这个页面

然后在这个界面'showResult.jsp'取得结果

  (${empty applicationScope.pollResult["案例剖析类"] ? 0 :applicationScope.pollResult["案例剖析类"]})

可以在这里返回结果    <input name="Button" type="button" class="btn_grey" value="返回" onClick="window.location.href='index.jsp'"></td>

原文地址:https://www.cnblogs.com/bluewelkin/p/3818035.html