File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes jstl question and page scope ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "jstl question and page scope ?" Watch "jstl question and page scope ?" New topic
Author

jstl question and page scope ?

Sami Sayeed
Ranch Hand

Joined: Oct 05, 2004
Posts: 39
Hi All,
This is the first program..
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

<%
java.util.Map map = new java.util.HashMap();

//created a map which is basically in the jsp page(page scope??? am i right)
%>
<c:set target="<%=map%>" property="dog" value="tom"/>

<a href="testset.jsp">click</a>
${map.dog}

<%=map.get("dog")%>// this is fine

Everything works fine in the first file...

This is the second jsp

<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

<%
java.util.Map map = new java.util.HashMap();

%>


<c:set target="${map}" property="dog" value="tom"/>// iam trying to use el to refer the map
// throws the following error
javax.servlet.ServletException
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:862)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:795)
org.apache.jsp.testsettarget_jsp._jspService(testsettarget_jsp.java:74)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:133)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
<a href="testset.jsp">click</a>
${map.dog}



<%=map.get("dog")%>
Guido Schoepp
Greenhorn

Joined: Oct 14, 2004
Posts: 21
Originally posted by Sami Sayeed:

This is the second jsp
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

<%
java.util.Map map = new java.util.HashMap();
%>

<c:set target="${map}" property="dog" value="tom"/>// iam trying to use el to refer the map
// throws the following error
javax.servlet.ServletException
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:862)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:795)
org.apache.jsp.testsettarget_jsp._jspService(testsettarget_jsp.java:74)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:133)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
<a href="testset.jsp">click</a>
${map.dog}

<%=map.get("dog")%>


Mixing of JSP scripting and EL is not a good idea.
<c:set> takes the value out of the PageContext object. But your declaration in the script (java.util.Map map = ...) doesn't make the map accessible for PageContext.

Try to use <jsp:useBean id="map" class="java.util.HashMap"/> instead of <% java.util.Map map = ...%>

Guido
Shiang Wang
Ranch Hand

Joined: Jun 20, 2003
Posts: 96
When you use scriptlet in JSP page, it is copied to the _jspService() of the generated servlet as it appear in the JSP. Therefore if you declare anything in the scriptlet, it is not an attribute in any scope, it is just an object that exist in the scriptlet that can only be shared by objects in the scriptlet.

Shiang


SCBCD, SCWCD, SCJP
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: jstl question and page scope ?