• Post Reply Bookmark Topic Watch Topic
  • New Topic

How can a form be populated on JSP start-up?

 
dekij ra
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Which servlet method would allow me to execute code for populating a form once a JSP is started without clicking on a Submit button. I tried init() but it doesn't work....Thanks

 
Devaka Cooray
Marshal
Posts: 5174
487
Chrome Eclipse IDE Google App Engine IntelliJ IDE jQuery Postgres Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should NOT use any java code in JSPs.
Did you really mean that method to be inserted into a JSP file? Or, perhaps, to a servlet?
 
dekij ra
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In my servlet. The code above is part of my servlet....
 
Devaka Cooray
Marshal
Posts: 5174
487
Chrome Eclipse IDE Google App Engine IntelliJ IDE jQuery Postgres Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry I'm still not understanding your problem. Can you please elaborate it little more?
If that is a servlet, why don't you use doGet() or doPost() method? Is this servlet properly mapped in the deployment descriptor? Can you show us that part?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65530
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
At a high level:
  • Make the form data available as a scoped variable -- beans are best for this
  • In the JSP, use the value attribute of the form elements to set their initial values from the form bean properties
  •  
    David Newton
    Author
    Rancher
    Posts: 12617
    IntelliJ IDE Ruby
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    And remember, there's only one instance of a servlet--init won't be called repeatedly. Just once, when the servlet is initialized.
     
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!