创建HttpSession时出错。 [英] Error while creating HttpSession.

查看:104
本文介绍了创建HttpSession时出错。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Login.jsp

Login.jsp

<form action="Welcome.jsp" method="post">
  <input type="text" name="Name" value="" />
<input type="password" name="Password" value="" />
<input type="submit" value="Login"> 
<input type="button" value="Forgot Password?"  önclick="location='ForgotPassword.jsp';" />
</form>





Welcome.jsp



Welcome.jsp

<%String loginName = request.getParameter("Name");
HttpSession session =request.getSession(true);
session.setAttribute("Login",loginName); %>




<form method = "POST" action="success.jsp">
Welcome <%=session.getAttribute("Login")%>
<input type="submit" value="Proceed" />
</form>



success.jsp


success.jsp

<form method="post" action="success.jsp">
Congrats <%=session.getAttribute("Login")%>
</form>







我的疑问是:

1.In欢迎。 jsp,对于第2行中的会话,我将错误视为重复本地变量会话。




My doubt is:
1.In Welcome.jsp,for session in line 2, im getting error as "Duplicate local variable session".

推荐答案

在JSP中,名为 session <的变量/ code>在每个JSP页面上都是隐式可用的,这是用户的会话。

换句话说,没有必要检索会话,因为它已经可以使用了。



所以,下面这行没有必要。

In JSP, a variable named session is implicitly available on each an every JSP page, which is the user''s session.
In other words, there is no need to retrieve the session, as it is already available to you.

So, the below line is not necessary.
HttpSession session =request.getSession(true);



现在,删除此声明排队并尝试。


Now, remove this declaration line and try.


这篇关于创建HttpSession时出错。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆