File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes Imp-How to execute a JSP file from java main Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Imp-How to execute a JSP file from java main " Watch "Imp-How to execute a JSP file from java main " New topic
Author

Imp-How to execute a JSP file from java main

L.John
Greenhorn

Joined: Aug 29, 2001
Posts: 24
Hi to All,
I am having a problem here. It would be kind of you to let me know how i vcould proceed further
how to execute a file(jsp) from main method?
a jsp file will publish the content to the database, actually some database
updation has to be done .
this jsp has to run every day at particular
time automatically .
The unix scheduler is already there now i have to prepare a java main
class to execute the jsp file......
I am new to JSP and dont have knowledge about it .
Any reply woul dbe highly appreciated .
Many Thanks
Bye
L.John
Madhav Lakkapragada
Ranch Hand

Joined: Jun 03, 2000
Posts: 5040
"L.John"

Your name doesn't agree with the javaranch guidelines. Please take a moment and re-register after reviewing the guidelines at http://www.javaranch.com/name.jsp
thanks for your cooperation.
- satya


Take a Minute, Donate an Hour, Change a Life
http://www.ashanet.org/workanhour/2006/?r=Javaranch_ML&a=81
ersin eser
Ranch Hand

Joined: Feb 22, 2001
Posts: 1072
Why do you have to use a .jsp file to do this ?
James Swan
Ranch Hand

Joined: Jun 26, 2001
Posts: 403
To take what you want to do (literally), you are asking how to send an Http Request to a JSP from a cmdline application.
Without knowing too much about what your requirements are, to call a JSP/Servlet/cgi-bin process you just need to use the java.net.* APIs.
In particular java.net.URL and java.net.HttpURLConnection.
Your "main()" will issue an Http request to the JSP in question.
The idea is that you need to know which parameters need to be passed into the JSP to make it function.
You will end up producing something like (depending on whether you want to POST or GET):

Anyway here is some example code to get you started (it attempts to do an HTTP POST):

Things can get a bit more complicated if there are firewall/proxy issues and also if some sort of authentication is done against the JSP, if so, send more details.
James.
Sarath Mohan
Ranch Hand

Joined: Mar 17, 2001
Posts: 213
Hi,
As one of our member has said, why do you need a jsp here?
In your doubt, it is not clear that, where the contents needs to be displayed.
If it is to be displayed on the browser,
why don't you use a Servlet with a proper thread implementation which will access the data from the db and make updations if necessary and display the content in daily basis?.
Thanks


Sarath Mohan
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Imp-How to execute a JSP file from java main