• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to calll a servlet onload when accessing a jsp page

 
Alyssa Kay
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64620
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic