0

I created a JSP page where I created a search form where the user can see some specific records of a student in the same page just below the search button. The search is done as follows:

"select col1, col2 from table1 where regn_no='"+regn_no+"'";

After displaying two columns(col1, col2), I have another button in the same jsp page to view the details to see details of the particular student based on the regn_no. The search button is working fine, but the view details button not. I do not know how to call the same servlet. Any help will be much appreciated.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
sujit
  • 251
  • 5
  • 12
  • 23

2 Answers2

2

The button's name=value pair get sent as HTTP request parameter as well. Assuming that you've

<input type="submit" name="search" value="Search">

and

<input type="submit" name="view" value="View">

then you can distinguish the button pressed in the servlet as follows:

if (request.getParameter("search") != null) {
    // Search button pressed.
} else if (request.getParameter("view") != null) {
    // View button pressed.
}

See also:


Unrelated to the problem, you've got a SQL injection risk there. Use PreparedStatement.

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
0

Assume that the two buttons in different forms. Both the forms can POST data to the same servlet. But you should make a marker to tell servlet which button is clicked. You can use a hidden input to do that. Say <input type="hidden" value="search"/> in search form, and <input type="hidden" value="viewdetail"/> in view form. Of cause, you can distinguish which button is clicked by the button name attribute which would be posted to servlet.

xiaowl
  • 5,177
  • 3
  • 27
  • 28
  • hey thnx for the answers frnds but plz tell me how to distinguish these two buttons when these two buttons are in two different forms?? How to call these two in the servlet page by a getParameter() or in any method????? – sujit Jan 18 '11 at 06:13
  • @sujit Where do you write your DB code, in a JSP page or servlet? – xiaowl Jan 19 '11 at 11:19
  • in a servlet....i m still trying to find the solution but not getting can anybody help me out here...plzzzzz – sujit Feb 07 '11 at 06:00