i think it is not possible.
when a client request a servlet, all the output are interpreted by the client as html code, and then the browser display the content in a web page manner.
if u are trying to use out.println("<%jsp..something>")
i think it will not work since all the output has been flushed to the client and the browser doesnt know how to compile your jsp code (since jsp is compiled in run time--during the request)
hope this can help
I posted this in another thread.
Here's some code that reads using a URL. This doesn't work with JSPs as the server executes JSP when it connects but it's useful for other file types. Note that the filename is a URI</h1>This is <code>show.jsp</code></h1>
<hr>
<%! String file = null; %>
<%! java.io.InputStream is = null; %>
<%
file = request.getParameterValues("filename")[0];
try {
is = (new java.net.URL(file)).openStream();
} catch (java.io.IOException ioe) { out.write(file + " not found!<br>"); }
java.io.BufferedReader in = new java.io.BufferedReader(new java.io.InputStreamReader(is));
String line = "";
%>
<pre>
<%
while((line = in.readLine()) != null) {
%>
<%=line%>
<%
}
%>
</pre>
Thanks everyone for your reply..I believe even when we open a URLConnection to display the JSP contents, it can identify Only the HTML tags and not the jsp tags..
For shubhrajit_c :
the question I asked is: Whether a servlet can throw the output if the file which it reads is a JSP file instead of a HTML file. Normally, this is the scenario when you need to display a thank_you page after a successful order, the servlet is able to display the HTML page and not a JSP page.
You need to get a "RequestDispatcher" for that JSP file and then "forward ()" the "ServletRequest" and "ServletResponse" to that JSP from your servlet. Processing is then handed over to that JSP file. Etc ...
Note: important words have been quoted. See references below for the people too lazy to look at the JDK docs or the Servlet SDK docs. Notice that "throw" clauses are not shown below.
ServletContext.getRequestDispatcher(java.lang.String path)
ServletContext.getNamedDispatcher(java.lang.String path)
ServletRequest.getRequestDispatcher(java.lang.String path)
RequestDispatcher.forward(ServletRequest request, ServletResponse response)
RequestDispatcher.include(ServletRequest request, ServletResponse response)