aspose 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


Win a copy of Java 8 in Action this week in the Java 8 forum!
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: 60072
    
  65

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
 
Similar Threads
executing a javascript function from a servlet
login servlet = login successful doesn't show
ApplicationDispatcher[/WebWormSales] PWC1231: Servlet.service() for servlet jsp threw exception java
Problem accessing a bean from a JSP
user authentication and dao