wood burning stoves 2.0*
The moose likes Servlets and the fly likes How to use the include() command in JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "How to use the include() command in JSP" Watch "How to use the include() command in JSP" New topic
Author

How to use the include() command in JSP

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
I want to include the output from another URL in my JSP.
This works fine if I write the syntax like and the output of the second servlet is embedded in the jsp page.
*** first case ***
<html>
<head>
<title>Test Page</title>
</head>
<body>
<% getServletConfig().getServletContext().getRequestDispatcher("servlet/com.mypack.ExternalOutput").include(request,response); %>

</body>
</html>
*** end ***
But, if I want to pass some parameters to another servlet in the form of URL rewriting then there is a problem like
*** second case ***
<html>
<head>
<title>Test Page</title>
</head>
<body>
<% getServletConfig().getServletContext().getRequestDispatcher("servlet/com.mypack.ExternalOutput?name=myname").include(request,response); %>
</body>
</html>
*** end ***
the error it is giving is that NoClassFoundException for com.mypack.ExternalOutput?name=myname
So, instead of treating it as URL it is treating whole URL as classname only
Is there any to overcome this ???
Brian Nice
Ranch Hand

Joined: Nov 02, 2000
Posts: 195
Bind you name=myname to the request object before doing the dispatch statement. That way, you do not have to include it on your URL line, but it will still be accessible to your servlet from the HttpRequest object.
HTH
Brian
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How to use the include() command in JSP
 
Similar Threads
Retriving Init Param of a JSP
jsp:include page="header.html" causes IllegalStateException
jsp:include page="header.html" causes IllegalStateException
Forward does now give exception
request URL reset to forwarded servlet