Guest User

Untitled

a guest
Jan 4th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. package servlets;
  2.  
  3. import java.io.IOException;
  4.  
  5. import javax.servlet.RequestDispatcher;
  6. import javax.servlet.ServletException;
  7. import javax.servlet.http.HttpServlet;
  8. import javax.servlet.http.HttpServletRequest;
  9. import javax.servlet.http.HttpServletResponse;
  10. import beans.CalculatorBean;
  11. @SuppressWarnings("serial")
  12. public class CalculateServlet extends HttpServlet
  13. {
  14. public void init() throws ServletException
  15. {
  16. super.init();
  17. log("servlet init");
  18. }
  19.  
  20. public void destroy()
  21. {
  22. log("servlet destroy");
  23. super.destroy();
  24. }
  25.  
  26. public void doGet(HttpServletRequest request,HttpServletResponse response)
  27. throws ServletException, IOException
  28. {
  29. String sx = request.getParameter("xvalue");
  30. String sy = request.getParameter("yvalue");
  31. String url = "";
  32.  
  33. CalculatorBean cb = new CalculatorBean();
  34. cb.setXvalue(sx);
  35. cb.setYvalue(sy);
  36. if(cb.isValid())
  37. {
  38. request.setAttribute("calc", cb);
  39. url = "WEB-INF/jsp/calculate.jsp";
  40. }
  41. else {
  42. request.setAttribute("calc", cb);
  43. url = "formdemo.jsp";
  44. }
  45.  
  46. RequestDispatcher dispatcher = request.getRequestDispatcher(url);
  47. dispatcher.forward(request, response);
  48. }
  49. }
Add Comment
Please, Sign In to add comment