<%JSP:include page="hello.jsp" %>

S

Shinya Koizumi

when i write if statement with JSP and want to include some jsp page
how can i include this <%JSP:include page="hello.jsp" %>?
In other word, how can i achieve the following code without getting
compile errors, because i have jsp:include tag in the scriplets

<%

if( h == true )
{
<JSP:include page="hello.jsp" />
}
else
{
<JSP:include page="nothello.jsp" />
}
%>
 
J

John C. Bollinger

Shinya said:
when i write if statement with JSP and want to include some jsp page
how can i include this <%JSP:include page="hello.jsp" %>?
In other word, how can i achieve the following code without getting
compile errors, because i have jsp:include tag in the scriplets

<%

if( h == true )
{
<JSP:include page="hello.jsp" />
}
else
{
<JSP:include page="nothello.jsp" />
}
%>

These days, scriptlet code is considered by many to be poor style.
Custom tags are the prevailing alternative, the JSTL tags foremost among
them. Nevertheless, if you want to do it with scriptlets then it would
look something like this:

<%
if (useHello) {
%>
<jsp:include page="hello.jsp" />
<%
} else {
%>
<jsp:include page="nothello.jsp" />
<%
}
%>

Note that
(1) There is no '%' in <jsp:include>
(2) The tag name is "jsp:include", NOT "JSP:include". It makes a
difference.
 
L

Luke Webber

John said:
These days, scriptlet code is considered by many to be poor style.
Custom tags are the prevailing alternative, the JSTL tags foremost among
them.

Ugh. JSP, Java and scriptlets are all part of a defined standard, but
fashion dictates that we should use black-box taglibs instead? I'm
sorry, but that's sheer idiocy.

Luke
 
R

Raymond DeCampo

Luke said:
Ugh. JSP, Java and scriptlets are all part of a defined standard, but
fashion dictates that we should use black-box taglibs instead? I'm
sorry, but that's sheer idiocy.

Well, if you would like to continue to mix presentation and business
logic, no amount of standards will stop you. In that case, I suggest
you investigate using RequestDispatcher.include() instead of the
equivalent JSP custom tag as you have above.

BTW, this particular "fashion" is based on well-earned experience in
building web apps. But I'm sure you know better, after all, you are
just starting out in the Java web world.

Ray
 

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,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top