Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to get the value saved in request scope in a servlet into a jsp page

 
santosh kimothi
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i saved some values in request scope in a servlet class.,,,

and i want to get that value in a jsp page....

can anybody tell me how to do this .........

its urgently needed....

 
Prasanna Lakshmi
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
request is an implicit object in JSP page.

So, you can try out like this.

request.getAttribute("the name you have used in servlet class");

Eg:

In servlet class

Boolean flag=true;
In servlet class request.setAttribute("sessVariable", flag);

In JSP page;

Boolean value = (Boolean)request.getAttribute("sessVariable");

NOTE: whater type of Object you have set to request, while retrieving you have to do the casting of same type. otherwise, you will be getting ClassCastException.

Hope this will resolve you problem.



Thanks
Prasanna M
 
santosh kimothi
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for your quick reply...... but my problem is still there..

i will specify my problem in detail...

i am having a servlet class as follows.... where i am saving the list(java.util.List) of records retrieved from db in a request scope...........

request.setAttribute(StudentConstants.STUDENT_LIST, studentList);

and in a jsp i want to display the contant of this list
and i am trying to do this....

<c:set var="s" value="${requestScope.StudentConstants.STUDENT_LIST)}" scope="request"></c:set>
<center>
<h1>Student Details</h1><br>
<table border="0" align="center">
<tr>
<td>Id</td><td>Name</td><td>Age</td><td>Quali</td><td>Course</td>
</tr>
<c:forEach var="s" items="${requestScope.studentlist}">
<tr>
<td><cut value="${s.studentId}" /></td>
<td><cut value="${s.studentName}" /></td>
<td><cut value="${s.studentAge}" /></td>
<td><cut value="${s.studentQualification}" /></td>
<td><cut value="${s.studentCourse}" /></td>
</tr>
</c:forEach>



but it is showing the following error message....
SEVERE: Servlet.service() for servlet jsp threw exception
org.apache.jasper.JasperException: /StudentDetails.jsp(3,0) According to TLD or attribute directive in tag file, attribute value does not accept any expressions
at org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:40)
 
Ramkumar Subburaj
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
in your tld file set rtexprvalueto true.

 
Pedro Fracarolli
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See, you're adding this attribute to your HttpServletRequest:



and you're accessing the attribute this way in your EL:



Excuse-me if I'm being ignorant, but shouldn't you actually need to use the value stored in the StudentConstants.STUDENT_LIST constant to retrieve the request attribute from the EL statement?



 
Srikkanth Mohanasundaram
Ranch Hand
Posts: 243
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem lies in here



Please remove the ) character in the EL expression. And why do you need this value to be set in there ? (You can do away with this line of code).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic