wood burning stoves*
The moose likes Servlets and the fly likes Hitting a JSP from a Servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Hitting a JSP from a Servlet" Watch "Hitting a JSP from a Servlet" New topic
Author

Hitting a JSP from a Servlet

Akram Reja
Greenhorn

Joined: Mar 13, 2001
Posts: 17
I have a strange problem to solve. My servlet reads the source code for the JSP from the database, and writes it to a file, which the user can later hit. Before writing the JSP to a file, the servlet has to 'hit' the JSP, to make sure that the JSP gets compiled with no errors. sendRedirect and forward do not work in this scenario, because the control has to return to the servlet after 'hitting' the JSP. Can any one suggest me a soluation? I am basically looking for some sort of 'curl(a unix command)' that I can use in my servlet. Any suggestions?
-Akram.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12756
    
    5
I can think of two possibilities:
1) dig into the Tomcat code and find out how to duplicate the effect of "hitting" the page by direct execution of the JSP page compiler.
2) address the page through a URLConnection to the localhost.
Bill
Akram Reja
Greenhorn

Joined: Mar 13, 2001
Posts: 17
Bill,
Thanks for your suggestions. I understand your first suggestion, but can you please elaborate on your second suggestion? Appreciate your help.
-akram
maha anna
Ranch Hand

Joined: Jan 31, 2000
Posts: 1467
Akram,
I think what Bill means is this. Open an URL connection and get the InputStream object and read the contents. I tested with a java application. You can include this code in servlet also.
When you run "java Test1" you will get

at the DOs command prompt.

regds
maha anna


Akram Reja
Greenhorn

Joined: Mar 13, 2001
Posts: 17
Thanks Maha. I didn't consider this possible at all. But, thanks to Bill and you, I have the solution.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Hitting a JSP from a Servlet
 
Similar Threads
JSP/FORM question
Life cycle of Jsp
SetFocus on re-displayed page
Sound in Servlet
How to upload a file from applet to the webserver ?