aspose file tools*
The moose likes Servlets and the fly likes JSP and request variables Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "JSP and request variables" Watch "JSP and request variables" New topic
Author

JSP and request variables

Anthony Smith
Ranch Hand

Joined: Sep 10, 2001
Posts: 285
Say I have a jsp page with something like this in it:
<% String page1 = null;
page1 = request.getParameter("page");
if (page1.equals("null"))
page1 = "";
out.println(page1);
%>
<jsp:include page="<%= page1 %>" flush="true" />
In order to get to this page you would have an address like the following: http://127.0.0.1:8080/Operations?page=test.jsp
I want to be able to get to this page like this http://127.0.0.1:8080/Operations without getting a Servlet Exception
SO in a nutshell it my link address contains a ?page=test.jsp then use it but if it does not just load the page still?
Is it possible?
PC RE
Greenhorn

Joined: Aug 28, 2001
Posts: 29
check out the servlet specification 2.3 chapter 11.
Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

which can be found here: http://jcp.org/aboutJava/communityprocess/first/jsr053/index.html

But you might be getting a servlet exception because of your code, not because of mappings...

In your code, you retrive the page parameter, and then make an equals(String) comparison. But if you call the page without ?page=test.jsp, this will throw a null pointer exception, which can be thrown by servlet runners as "servlet exception"... look farther down in your stack trace, you may have a 'root cause: java.lang.NullPointerException' And now I've just noticed that you're seeing if it's null by comparing it to "null". You really mean:

Also, you should consider re-writing it to NOT do the include if it's null.


[This message has been edited by Mike Curwen (edited September 10, 2001).]
Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

Hehe,

While checking if there were any replies, I realized that once again, my boolean logic was the exact opposite of my first guess.

It should be && inside the if statement.
sea yin
Greenhorn

Joined: Sep 09, 2001
Posts: 5
<% String page1 = "";
page1 = request.getParameter("page");
if (page1.equals(""))
out.println(page1);
%>
<jsp:include page="<%= page1 %>" flush="true" />
Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

sea:

That will throw a nullpointer exception in some cases.
 
wood burning stoves
 
subject: JSP and request variables