开发者

How can i fetch any string value in JSP page

开发者 https://www.devze.com 2023-02-12 21:33 出处:网络
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 t

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号