jsp:include - including a servlet problem
Hi there,
I want to use a jsp:include inhome.jsp to include a servlet,NavigationServlet.NavigationServlet queries a database, creates a bean and stores the bean in the request before forwarding tosidebar.jsp.sidebar.jsp uses the bean stored in the request to output some data.
Is this possible, because when I try, the place where I expectsidebar.jsp to appear inhome.jsp is blank.
I know that the servlet is being called correctly so Im thinking maybe that jsp:include just does not have these capabilities. I have also attempted to try using the include directive but my IDE tells me that it can't findNavigationServlet. I can't work out what the path should be.
Any ideas? Thanks!
[780 byte] By [
bigadjayea] at [2007-11-27 11:24:42]

# 1
As I understand it:
A JSP file is compiled into a servlet automatically by your server when its called. What you are trying to do when including a servlet in a JSP page is essentially including a servlet in a servlet which cant be done. The include directive is to include html or JSP tags in the existing JSP page which is then all compiled together into a servlet.
The usual solution is to have two JSP pages and a servlet. The first JSP posts back to your servlet that acts as a controller servlet, receiving urls from any JSP pages, processes business logic (update button clicks, etc from the JSP page), then forwards either to the original JSP page or another JSP page. The servlet puts data it got from performing business logic (ie, accessing the database) in request scope so the JSP page it calls can get the data out of request scope and display it.
# 2
Agreed the include directive is not what you are after here.
<jsp:include> should be the way to go. However what you need to jsp:include is the URL to access that servlet (ie the servlet mapping set up in web.xml), not the name of that servlet explicitly.
cheers,
evnafets
# 3
This is what I tried but it did not work... I am pretty sure that my jsp:include is reaching my servlet ok because if I mistype the URL I get an error. When I type it correctly there are no errors.
But it seems that using jsp:include to include a Servlet which forwards to a JSP page is not possible which is what I want to do.
Do you know if it is possible?
# 4
Sorry evnafets, I re-read ur advice and re-checked my code and you were right again. I was missing the "/" at the beginning of my URL! Thanks, u've been very helpful to me :D