你取出的值当然是空,因为你并没有把表单的各个值取出来,默认的当然是空。你可以这样做:三个jsp页面:jsp1.jsp的代码为:
<%@ page contentType="text/html;charset=UTF-8" %>
<%@page import="java.util.*"%>
<html>
<head>
</head>
<body >
<%!String username,password,checkbox1;%>
<FORM name="form1" method="post" action="jsp2.jsp">
<INPUT type="text" name="username">
<INPUT type="text" name="password" />
<INPUT type="Submit" name="submit" >
</FORM>
</body>
</html>
jsp2.jsp的代码为:
<%@ page contentType="text/html;charset=UTF-8" %>
<html>
<head>
</head>
<body>
<% String username=request.getParameter("username");
String password=request.getParameter("password");
%>
<%
session.putValue("username",username);
session.putValue("password", password) ;
%>
<jsp:forward page="jsp3.jsp" />
</html>
jsp3.jsp的代码为:
<%@ page contentType="text/html;charset=UTF-8" %>
<html>
<head>
</head>
<body>
<%=session.getValue("checkbox1")%>
<%=session.getValue("username")%>
<%=session.getValue("password") %>
</body>
</html>
试试看,此实例帮你理解session的作用和request的作用。
<%@ page contentType="text/html;charset=UTF-8" %>
<%@page import="java.util.*"%>
<html>
<head>
</head>
<body >
<%!String username,password,checkbox1;%>
<FORM name="form1" method="post" action="jsp2.jsp">
<INPUT type="text" name="username">
<INPUT type="text" name="password" />
<INPUT type="Submit" name="submit" >
</FORM>
</body>
</html>
jsp2.jsp的代码为:
<%@ page contentType="text/html;charset=UTF-8" %>
<html>
<head>
</head>
<body>
<% String username=request.getParameter("username");
String password=request.getParameter("password");
%>
<%
session.putValue("username",username);
session.putValue("password", password) ;
%>
<jsp:forward page="jsp3.jsp" />
</html>
jsp3.jsp的代码为:
<%@ page contentType="text/html;charset=UTF-8" %>
<html>
<head>
</head>
<body>
<%=session.getValue("checkbox1")%>
<%=session.getValue("username")%>
<%=session.getValue("password") %>
</body>
</html>
试试看,此实例帮你理解session的作用和request的作用。
解决方案 »
- tomcat配置与否的问题
- hibernate中的lazy与fetch有什么区别
- 高分求解:用Tomcat6/7 Struts2 spring项目关闭时会memory leak.
- 谁能给我讲一下jni具体点的
- hibernate中save和merg的区别
- Tomcat如何动态去更新lib下的一个jar包,可以停止Tomcat
- 一个关于EJB返回值的解决方案,请大家对此方法的优缺点发表意见,跟贴者有分。。。
- ejb接口、 图片存储
- json拼接的字符串,日期格式转换问题
- 强引用、软引用、弱引用、虚引用在实际场景中的运用
- 如何通过计算机名连接数据服务器
- tomcat部署后不用重起应用就能生效,如何配置(在线中)
<% String username=request.getParameter("username");
String password=request.getParameter("password");
%>
<%
session.putValue("username",username);
session.putValue("password", password) ;
username , password 的值不为NULL.
session.putValue("password", password) ;
会不会是putValue的问题啊,你改成setAttribute()吧。
<% String username=request.getParameter("username");
String password=request.getParameter("password");
%>
<%
session.setAttribute("username",username);
session.setAttribute("password", password) ;
%>
<jsp:forward page="jsp3.jsp" />
</html>
jsp3.jsp的代码为:
<%@ page contentType="text/html;charset=UTF-8" %>
<html>
<head>
</head>
<body>
<%=session.getAttribute("checkbox1")%>//这个空不空啊
<%=session.getAttribute("username")%>
<%=session.getAttribute("password") %>
<%=session.getAttribute("checkbox1")%>//