JSP Dynamic Includes

AH_Viper

Spy
Joined
Jul 20, 2003
Messages
605
Reaction score
0
Anyone know how the hell to do dynamic includes like PHP in JSP?
 
I think it's something like...

<%@include file="file.jsp" %>
 
Yeah that works, but im trying to include from a querystring.

more along the lines of:

<%
String startpage = "pages/";
String middlepage = request.getQueryString("qpage");
String endpage = ".jsp";
String dopage = startpage + middlepage + endpage;
%>
<jsp:include page="<%=dopage%>" flush="false"/>

Keep getting this error:

Note: sun.tools.javac.Main has been deprecated.
/acfr/index.jsp:233: Wrong number of arguments in method.
String middlepage = request.getQueryString("qpage");
^
1 error, 1 warning

EDIT:: That ^ points to the "(" of the getQueryString method
 
Don't use JSP... ever, but...

...when doing a quick search on request.getQueryString(), I didn't come across a single use of it where it took any parameters.

It seems to only have an arity of 0. Which would explain why the error said you passed in an incorrect number of agruments.

What exactly are you expecting request.getQueryString("qpage") to do different from request.getQueryString() ? Are you trying to parse for a variable 'qpage' in the query? If that's the case then request.getParameter("qpage") might be the method you're looking for.
 
ok manged to get it. For anyone thats interested heres my code:

<%
String startpage = "pages/";
String middlepage = "home";
if(request.getParameter("qpage") != null){
middlepage = request.getParameter("qpage");
}
String endpage = ".jsp";
String dopage = startpage + middlepage + endpage;
%>

<jsp:include page="<%=dopage%>" flush="false"/>
 
Ansur said:
And why might that be?
Easy & powerful (though bit heavy)!

Probably a misunderstanding here...
Not telling people not to use it... just saying that I never use it; not because it isn't usefull but because I've never had a real reason to use it.

But that wasn't the point of my post... the point was to suggest to AH_Viper to use getParameters instead of getQueryString for parsing the query string for specific variables.
 
Are there so many JSP programmers in this board. :eek:

What advantages has JSP to other languages like PHP or ASP?
 
Dunno, use PHP myself. Just doing JSP as part of my course ;)

JSP seems a good way to keep database code away from your HTML, its very modular, and once youve got a good set of "beans" (modules of Java code) you can use them again and again
 
one said:
What advantages has JSP to other languages like PHP or ASP?
Reliability and security are probably the biggest (if not only) advantages over using PHP. You will mostly find JSP on larger corporate web sites or networks, I actually don't see any reason why people would use it on smaller projects.
 
No Limit said:
Reliability and security are probably the biggest (if not only) advantages over using PHP. You will mostly find JSP on larger corporate web sites or networks, I actually don't see any reason why people would use it on smaller projects.
Why don't you see a reason for people to use it on smaller projects if it has a better reliability and security? That's important for small projects, too.
 
Back
Top