简体   繁体   中英

How can i fetch any string value in JSP page

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.

Please help me out.

Thanks in advance.

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.

From the servlet, set the file name in request context:

request.setAttribute("filename", fileNameStr );

In JSP write:

<%=request.getAttribute("filename")%>

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");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM