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

c:set confusion

 
Jay Alexander
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am attempting the example on page 444&445. I am not understanding something. According to the text you should be able to set a scope variable in page, request, etc.... However, I was trying an example of setting a request scope variable in a JSP page, and was attempting to extract it the servlet's doPost() method from the request, but the value continued to be null. I tried the following:
<c:set var="variable1" scope="request" value="somevalue /> &
<c:set var="variable2" scope="session" value="somevalue />. I was able to get the value from the session in the doPost() with
request.getSession().getAttribute("variable2"), but unable to get it from the request with request.getAttribute("variable1").
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess you are accessing the JSP first, and then submitting to your servlet, which means using two different requests.

1. BROWSER -- requestOne --> JSP
2. JSP -- requestTwo --> Servlet

The request to your JSP ends when the page is displayed.
So variable1 will be visible until the request to your JSP page is completed.

Going from your JSP to your servlet will start a NEW request (requestTwo), where variable1 is not included.

To make variable1 visible to your servlet, you could for instance forward the request of your JSP to the servlet :

In this case, you'll keep the same request :
BROWSER -- requestOne --> JSP -- requestOne --> Servlet
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic