I wish to include a file in JSP, but the file is result from database query.
Therefore, i would like to call a servlet in JSP using the following tag:
<%@ include file="XXX" %>
However, the result came out with the following exception:
generated the following parse exception: org.apache.jasper.compiler.CompileException:
Bad file argument to include
You may suggest that i straightfowardly include another jsp file and inside that jsp
file call the database to get the data and present it. However, i wish to it in separate
tier (business tier) in my servlet and business class. I feel weird when my JSP creating
connection to the database because it suppose to be the presentation layer.
thanks.
-
Include Servlet in JSP (4 messages)
- Posted by: Lee Eng Leong
- Posted on: March 25 2002 19:42 EST
Threaded Messages (4)
- Include Servlet in JSP by Ad Reijngoudt on March 26 2002 10:31 EST
- Include Servlet in JSP by Saruman White on March 26 2002 12:05 EST
- Include Servlet in JSP by Lee Eng Leong on March 27 2002 19:31 EST
- Include Servlet in JSP by Sheng Sheen on March 26 2002 16:58 EST
-
Include Servlet in JSP[ Go to top ]
- Posted by: Ad Reijngoudt
- Posted on: March 26 2002 10:31 EST
- in response to Lee Eng Leong
Hi,
I don't think you can (or should) include a servlet in a JSP. You can do either of 2 things:
- use the servlet directly (without the JSP)
- from within the JSP, call a Java-class which responses with the desired data to display, eg:
<%= someClass.someMethod(someArg) %> -
Include Servlet in JSP[ Go to top ]
- Posted by: Saruman White
- Posted on: March 26 2002 12:05 EST
- in response to Lee Eng Leong
You should use <jsp:include page="XXX"/> instead of <%@ include file="XXX" %>. The latter just means merging before compilation, which apparently not what you want to do. 'jsp:include' actually includes response from XXX into 'parent' JSP response.
-
Include Servlet in JSP[ Go to top ]
- Posted by: Lee Eng Leong
- Posted on: March 27 2002 19:31 EST
- in response to Saruman White
Thanks for the through explanation.
I had solved my problem. -
Include Servlet in JSP[ Go to top ]
- Posted by: Sheng Sheen
- Posted on: March 26 2002 16:58 EST
- in response to Lee Eng Leong
why don't you have the servlet do the DB call and then forward on to the JSP instead of including the Servlet call in JSP. That would be more of a MVC II paradigm.