JSP向Servlet传值
我写了个测试类:MyJsp01.jsp<formaction="testRequestsetAttribute/MyJsp02.jsp"method="post"><%s...
我写了个测试类:
MyJsp01.jsp
<form action="testRequestsetAttribute/MyJsp02.jsp" method="post">
<%
session.setAttribute("val","mark");
%>
<input type="submit" value="submit">
</form>
MyJsp02.jsp
<%=session.getAttribute("val") %>
<form action="testRequextGetAttribute" method="post">
<input type="submit" value="submit">
</form>
servlet:
HttpSession session = null;
String mark=session.getAttribute("mark").toString();
out.print(mark);
MyJsp01.jsp提交给MyJsp02.jsp,session值取到,MyJsp02.jsp提交给servlet,报空指针异常
异常行:String user=session.getAttribute("user").toString();
前辈们帮忙分析下原因
写错个地方:servlet取值getAttribute("val"),不是"mark"
异常行:String mark=session.getAttribute("val").toString(); 展开
MyJsp01.jsp
<form action="testRequestsetAttribute/MyJsp02.jsp" method="post">
<%
session.setAttribute("val","mark");
%>
<input type="submit" value="submit">
</form>
MyJsp02.jsp
<%=session.getAttribute("val") %>
<form action="testRequextGetAttribute" method="post">
<input type="submit" value="submit">
</form>
servlet:
HttpSession session = null;
String mark=session.getAttribute("mark").toString();
out.print(mark);
MyJsp01.jsp提交给MyJsp02.jsp,session值取到,MyJsp02.jsp提交给servlet,报空指针异常
异常行:String user=session.getAttribute("user").toString();
前辈们帮忙分析下原因
写错个地方:servlet取值getAttribute("val"),不是"mark"
异常行:String mark=session.getAttribute("val").toString(); 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询