This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Servlets and the fly likes Unable to include JSP file in Servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Unable to include JSP file in Servlet" Watch "Unable to include JSP file in Servlet" New topic
Author

Unable to include JSP file in Servlet

Srividya Venkataraman
Greenhorn

Joined: Dec 18, 2005
Posts: 3
In the Request Dispatcher, I am including a JSP file, It is not getting included. But when i include a html file its getting reflected. Please let me know what the problem is.
I am using


Attached Code Snippet:
public final void include(final String resourceName)
throws FatalException
{
include( getDispatcher( resourceName ) );
}

private void include(final RequestDispatcher rd)
throws FatalException
{
try {
wr.save(req, Request.INCLUDED_REQUEST);
rd.include(req, res);
wr.unsave(req);// for static resources
}
catch(final IOException ioe) {
throw new FatalException("Dispatcher", "include",
"Failed to include:: " + Logger.eoln()
+ ioe.toString());
}
catch(final ServletException se) {
throw new FatalException("Dispatcher", "include",
"Failed to include:: " + Logger.eoln()
+ se.toString());
}
}
Scott Dunbar
Ranch Hand

Joined: Sep 23, 2004
Posts: 245
Is it not getting included or is it not getting interpreted? Take a look at the HTML that is generated to see. I'm guessing that the JSP file is being included but your application server is simply passing the output through. By default the app server is not going to parse the output of your servlet to determine if it contains JSP artifacts.


<a href="http://forums.hotjoe.com/forums/list.page" target="_blank" rel="nofollow">Java forums using Java software</a> - Come and help get them started.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61084
    
  66

Originally posted by Scott Dunbar:
By default the app server is not going to parse the output of your servlet to determine if it contains JSP artifacts.


That is true of text emitted directly to the output stream, but when using a request dispatcher include, as in this example, the targetted resource will be interpreted.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Scott Dunbar
Ranch Hand

Joined: Sep 23, 2004
Posts: 245
Yep, Bear, I spaced that one. Srividya, there is some information missing - what is the "wr" member variable and what do the methods you're calling do? Also, I'd assume by your post that you're not getting an exception thrown, correct?
Srividya Venkataraman
Greenhorn

Joined: Dec 18, 2005
Posts: 3
Yes Scott, It is not getting an exception thrown.
I am getting java file created under work directory and its corresponding class file is also created for JSP, but it is not getting reflected in the Screen as it does for a html file.

I am using Tomcat 4.x, Do I need to do anything at the Webserver side to make these JSP recognized.

wr is an Request Object.

void save(final HttpServletRequest req, String saveType)
throws FatalException
{
if (req == null)
throw new FatalException("Request", "save",
"Http Request argument was null.");

saveType = checkNull("Save Type", saveType);
if (!saveType.equals(FORWARDED_REQUEST) &&
!saveType.equals(INCLUDED_REQUEST))
throw new FatalException("Request", "save",
"Save type [" + saveType + "] can " +
"only be either " + FORWARDED_REQUEST
+ " or " + INCLUDED_REQUEST + ".");


req.setAttribute(SAVED_REQUEST_ATTRIBUTE, this);
if (saveType.equals(INCLUDED_REQUEST))
includeCount++;
}
// -----------------------------------------------------------------------
// unsaves itself for included requests.
void unsave(final HttpServletRequest req)
throws FatalException
{
if (req == null)
throw new FatalException("Request", "save",
"Http Request argument was null.");

// for static resources
req.removeAttribute(SAVED_REQUEST_ATTRIBUTE);
includeCount--;
}



// -----------------------------------------------------------------------
private void include(final RequestDispatcher rd)
throws FatalException
{
try {
wr.save(req, Request.INCLUDED_REQUEST);
rd.include(req, res);
wr.unsave(req);// for static resources
}
catch(final IOException ioe) {
throw new FatalException("Dispatcher", "include",
"Failed to include:: " + Logger.eoln()
+ ioe.toString());
}
catch(final ServletException se) {
throw new FatalException("Dispatcher", "include",
"Failed to include:: " + Logger.eoln()
+ se.toString());
}
}
// -----------------------------------------------------------------------
// includes a request to a resource in different web application
public final void include(final String application,
final String resourceName)
throws FatalException
{
include( getDispatcher( application, resourceName ) );
}
// -----------------------------------------------------------------------
// includes a request to a resource in same web application
public final void include(final String resourceName)
throws FatalException
{
include( getDispatcher( resourceName ) );
}
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Unable to include JSP file in Servlet