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

How to calll a servlet onload when accessing a jsp page

Alyssa Kay
Greenhorn

Joined: Jan 20, 2009
Posts: 8
Hi everyone,

I would like to call a servlet when the user accesses a jsp page. This servlet returns an arraylist of values to populate a table.

I have added <body onload="document.form.submit();"> to call and execute the controller servlet. This works fine, although it keeps on executing this action over and over and over!

Is this a valid way of approaching the problem, I would appreciate your advice.

If you can help please post a response.

Thanks



The servlet -


Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61601
    
  67

Yes. You are going about it backwards. The JSP should not invoke the servlet, the servlet should invoke the JSP. Your URLs should not target JSPs directly, but rather, servlet page controllers that do exactly the types of thing you are talking about here.

See this article for a discussion of the patterns involved.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to calll a servlet onload when accessing a jsp page