• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Imp-How to execute a JSP file from java main

 
L.John
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5040
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"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
 
ersin eser
Ranch Hand
Posts: 1072
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why do you have to use a .jsp file to do this ?
 
James Swan
Ranch Hand
Posts: 403
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 213
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic