2

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.

  • state what is that you would like to achieve. your question is very generic to provide proper answer – Aravind Yarram Feb 24 '11 at 05:34
  • Index.jsp page send request which handles by FileAction servlet class and this action class invoke the FileManagement java class which manipulate and generate a File-Name. This is what i want to access the File-Name in my second JSP page if everything got successful. –  Feb 24 '11 at 05:39
  • Hi everyone, I did it myself. BTW thanks to all of you. –  Feb 24 '11 at 06:16

3 Answers3

1

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.

MeBigFatGuy
  • 28,272
  • 7
  • 61
  • 66
1

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

request.setAttribute("filename", fileNameStr );

In JSP write:

<%=request.getAttribute("filename")%>
rahulmohan
  • 1,285
  • 11
  • 19
  • 1
    Why would you suggest a [discouraged](http://stackoverflow.com/questions/3177733/how-to-avoid-java-code-in-jsp-files) way of writing *scriptlets*? Just do `${filename}`. – BalusC Feb 24 '11 at 12:40
0

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