accessing context-param from jsp

H

harryos

hi
in my jsp page I want to access a parameter value given in web.xml

<html>
<jsp:include page="<%=application.getInitParameter("external-include")
%>"/>
<body>
....
</body>
</html>

where web.xml has
<context-param>
<param-name>external-include</param-name>
<param-value>WEB-INF/jspf/header_tag.jsp</param-value>
</context-param>

When i run the jsp page in tomcat i get an error >>
/includebyparam.jsp(6,22) Attribute value application.getInitParameter
("external-include") is quoted with " which must be escaped when used
within the value.

Is there something wrong with the way i coded it? Can someone help me
correct it
thanks
harry
 
H

harryos

<jsp:include page="<%=application.getInitParameter("external-include")
%>"/>
Attribute value application.getInitParameter
("external-include") is quoted with " which must be escaped when

Is there something wrong with the way i coded it? Can someone


to answer myown question ,the error doesn't happen when the code is
written this way

<% String headerpagename=application.getInitParameter("external-
include"); %>
<jsp:include page="<%=headerpagename%>" />

harry
 
T

Tim Slattery

harryos said:
Attribute value application.getInitParameter


to answer myown question ,the error doesn't happen when the code is
written this way

<% String headerpagename=application.getInitParameter("external-
include"); %>
<jsp:include page="<%=headerpagename%>" />

Look at the way to coded it first. You've got a quoted string within a
quoted string, and you're using double quotes (") to delimit both
strings. So the parser sees the second set of double quotes, which you
intend to start the inner string, as the end of a quoted string. I'm
not sure what the solution to that is, you might use single quotes for
the inner string, or maybe you have to escape the double quotes (\" or
something like that). And you found a way around it by eliminating
nested strings.
 
L

Lew

Use single quotes to set off the attribute, but really, scriptlet in your JSP?
Shame!
Attribute value application.getInitParameter
("external-include") is quoted with " which must be escaped when

Is there something wrong with the way i [sic] coded it? Can someone
to answer myown question ,the error doesn't happen when the code is
written this way

<% String headerpagename=application.getInitParameter("external-
include"); %>

Even worse. Move all non-presentation logic into .java source and out of your
JSP. Learn JSTL. Study MVC.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top