Adding multiple forms for a single java Servlet

Lucian Mitea :

I was trying to learn about java servlet and JSP. At some time I hit this problem. I have this ADMIN.jsp, where I wrote all the HTML forms for CRUD operations. The thing I don't know is how to call whatever form I what from my AdminServelt, for instance if I click the Delete button on web interface, I want my servlet to know what form to choose from JSP and delete whatever I decide throw the form's input.

Ankit :

You can to enter one hidden parameter like

<input type="hidden" name="purpose" value="C/R/U/D">

in the jsp file.

On servlet you will pass value of parameter into new variable

    String decisionParam = request.getParameter("purpose");

if(decisionParam.equals("C"){ 

//process create logic
}
else if(decisionParam.equals("R")) {
//process read logic
}

and so on

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=81161&siteId=1