Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Can JSP's include servlets?

 
verduka fox
Ranch Hand
Posts: 178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a jsp file that currently includes 4 other files:

However, I now need to change these included files from .jspf's to servlets. Can servlets be included in JSP files? I have tried:

but I get an error: Bad file argument to include. I also prepended <%= request.getContextPath() %>/ before "servlet/com.mycompany.myproject.MyServlet" and received the same error.
Please advise. Thanks in advance.
 
arul murug
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
You can�t include the output of a servlet using static include.
Try using dynamic include like this
<jsp:include page="servlet/....">
 
verduka fox
Ranch Hand
Posts: 178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried changing my code to:

and received this error:
javax.servlet.ServletException: ERROR: Cannot forward. The response has already be
en committed.
Please advise. Thanks in advance.
 
arul murug
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
umm..I am not sure whether response will be comitted when you add "flush=true".I think it shouldn't.
May be you can try removing "flush=true".

Arul
 
verduka fox
Ranch Hand
Posts: 178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I removed the flush="true" part of the jsp include tag. This time I received this error on a 500 page:
JSPG0080E: Invalid jsp:include tag: org.apache.jasper.JasperException: JSPG00
80E: Invalid jsp:include tag
The code is:
<td><jsp:include page="servlet/com.mycompany.myproject.MyServlet" /></td>
Core Servlets and JavaServer Pages by Marty Hall says:

The jsp:include element has two required attributes, as shown in the sample below: page (a relative URL referencing the file to be included) and flush (which must have the value of true).
<jsp:include page="Relative URL" flush="true" />

Any other ideas?
 
Joel McNary
Bartender
Posts: 1840
Eclipse IDE Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is your servlet forwarding to a different URL? Remember, once you start writing to the output stream, you cannot forward. The JSP starts writing to the output stream, so when the servlet gets included and attempts to forward it will thorw that error.
 
arul murug
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
According to JSP specification, �flush� attribute in <jsp:include> is a optional attribute with �false� as default if don�t specify it. I am not sure in what context �Core Servlets and JavaServer Pages by Marty Hall says:� says.
You don't need to give the flush attribute,but I don't know why you are invalid include exception.
 
arul murug
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Link for JSP1.2 specification
JSP 1.2 Specification
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic