【发布时间】:2014-09-10 20:01:56
【问题描述】:
null 中 JSP 中的用户名,为什么?在 servlet 中我没有 null 参数。 name 和 familiya 运行良好,只有 username 是 null。
小服务程序:
HttpSession session = request.getSession();
session.setMaxInactiveInterval(30);
session.setAttribute(username, uservalue);
session.setAttribute(name, namevalue);
session.setAttribute(familiya, familiyavalue);
PrintWriter out = response.getWriter();
out.println(uservalue); ==== Is NOT null
JSP:
<%
HttpSession ses = request.getSession();
String name =(String)ses.getAttribute("name");
String familiya =(String)ses.getAttribute("familiya");
String username = (String)ses.getAttribute("username");
//out.println(name); out.println(familiya);
out.println(username);
%>
<a href="http://localhost:8080/siteg/index?user=<%=username%>"><%=name %> <%=familiya %> </a>
【问题讨论】:
-
与 servlet 不同,在 JSP 中您不必执行
HttpSession ses = request.getSession();,因为它已经有一个名为session的HttpSession对象。 -
谢谢,不知道,已修复