• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Unable to include JSP file in Servlet

 
Srividya Venkataraman
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 245
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64959
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Scott Dunbar
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ) );
}
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic