This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes c:set confusion Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "c:set confusion" Watch "c:set confusion" New topic
Author

c:set confusion

Jay Alexander
Greenhorn

Joined: Dec 11, 2005
Posts: 1
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

Joined: Nov 24, 2005
Posts: 14687
    
  16

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


[My Blog]
All roads lead to JavaRanch
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: c:set confusion