jQuery in Action, 3rd edition
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 Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "c:set confusion" Watch "c:set confusion" New topic

c:set confusion

Jay Alexander

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é

Joined: Nov 24, 2005
Posts: 14688

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
It's not a secret anymore!