If any "ID" set with value in Servlet Class then How can i access that value on my jsp page. As i know there are several methods which helps to fetch the value by using Session management but i am tired of do it.
Pleas开发者_如何学编程e help me out.
Thanks in advance.
From the servlet, set the file name in request context:
request.setAttribute("filename", fileNameStr );
In JSP write:
<%=request.getAttribute("filename")%>
Typically the servlet calls HttpServletRequest.setAttribute to place a key value pair in the request. Then the jsp page can access this value thru the 'request' jsp variable.
Very simple via session, and you don't need to deal with passing parameters between pages.
File 1:
String strVal = "one";
session.setAttribute("strVal",strVal);
File 2:
String strVal = (String)session.getAttribute("strVal");
精彩评论