<form action="${pageContext.request.contextPath}/myservlet" method="post">
<input type="submit" name="button1" value="Button 1" />
<input type="submit" name="button2" value="Button 2" />
<input type="submit" name="button3" value="Button 3" />
</form>
with
@WebServlet("/myservlet")
public class MyServlet extends HttpServlet {
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
MyClass myClass = new MyClass();
if (request.getParameter("button1") != null) {
myClass.function1();
} else if (request.getParameter("button2") != null) {
myClass.function2();
} else if (request.getParameter("button3") != null) {
myClass.function3();
} else {
// ???
}
request.getRequestDispatcher("/WEB-INF/some-result.jsp").forward(request, response);
}
}
I am not getting the desired output as in this example. The method runs independently through servlet, but these if else conditions are not working.
Aucun commentaire:
Enregistrer un commentaire