• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Can JSP's include servlets?

 
Ranch Hand
Posts: 178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Bartender
Posts: 1844
Eclipse IDE Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Link for JSP1.2 specification
JSP 1.2 Specification
 
When people don’t understand what you are doing they call you crazy. But this tiny ad just doesn't care:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic