This question already has an answer here:
I am new to JavaEE and have a query regarding a servlet that has multiple methods.
I want to know how I can call a specific method on a servlet, when I click "Submit
" button in JSP.?
Someone have suggested to use HTML hidden fields
but I have no idea on how to implement them in Jsp.
Hidden fields in a JSP are the same as in HTML:
Then in your servlet you can do
i dont think having 3 buttons is the best solution,basis on the logic and parameters method asked,
i believe this can be an accurate solution-
On the basis of parameters passed ,we can have 2 methods to access different actions via javascript-
1)getting values from user,checking them in javascript.
2)getting values from user,checking them in javascript,assigning values to hidden variables accordingly,calling servlets and using those hidden values.i have elaborated method1.
Depends on which method you want to call. Assuming that the URL Pattern declared for your servlet in
web.xml
is/myservlet*
,For
doGet
, just use a URLFor
doPost
, use a form.You can just give the submit button a specific name.
The name-value pair of the pressed button is available as request parameter the usual way.