Reputation: 43
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.
Upvotes: 4
Views: 1861
Reputation: 11
Write a form like this in JSP:
<form method="post" action="/AdminServlet?edit"> </form>
This one is for Edit, for example. And you can try something like this in AdminServlet, if you want to check if you clicked on Edit button:
if (request.getQueryString().equals("edit")) {}
Upvotes: 1
Reputation: 2256
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
Upvotes: 1