jsp获取的session直接从内置对象获取,用el表达式显示就可以了。
java后台设置session方法:
HttpSession session=request.getSession();
session.setAttribute("sname", "test-session");//session设值
request.setAttribute("rname","test-request");//request设值
request.getRequestDispatcher("index.jsp").forward(request, response);
${sname}//session取值
${rname}//request取值
jsp页面用el表达式取值方法:
用<%=request.getSession().getAttribute('sname')> 就可以取到值了。
String s_name= (String) request.getSession().getAttribute("name");
if(s_name==null)
s_name = "";
String string = (String)session.getAttribute("name");
Session.getAttribute("name");
getname