This week's giveaways are in the MongoDB and Jobs Discussion forums.
We're giving away four copies of Mongo DB Applied Patterns and 4 resume reviews from Five Year Itch and have the authors/reps 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
Register / Login


Win a copy of Mongo DB Applied Patterns this week in the MongoDB forum
or a resume review from Five Year Itch in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Servlets
Reply 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: 56150
    
  13

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.


[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About 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://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Unable to include JSP file in Servlet
 
Similar Threads
Servlet downloads Excel file ok but also attempts Servlet & JSP files !!
Ignoring ParsingExceptions for quotes
How to Return a File using Servlet
Use of getResourceAsStream() ??????????
Indicate non-fatal error without Exception