0

i have worked with php for over 2 years now ,i have just recently shifted to my first project in java

i have a form on which i am redirecting to servlet though post, here is the code.

  public class Login extends HttpServlet {
     private static final long serialVersionUID = 1L;

     @Autowired
     EnfantsHibernateDAO enfantsdao;

        public Login() {
            super();
            // TODO Auto-generated constructor stub
        }


     protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

      request.getRequestDispatcher("/WEB-INF/views/dashboard.jsp").forward(request,response);
     }

     @Override
     protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

      req.getRequestDispatcher("/WEB-INF/views/dashboard.jsp").forward(req, resp);

     }

now inside doPost method i am calling a jsp page, which loads just fine i am facing an issue, after loading the dashboard.jsp from doPost when i refresh the dashboard.jsp page it shows me the form re submission alert,

now working with php what i do is redirect to another method from the post method and then load the view from that other method so that i may not get form re submission error, my question is how i can i achieve something similar with servlet?

uneeb meer
  • 682
  • 2
  • 7
  • 27
  • So your problem is actually the alert you see when you re-submit the page? This is normal browser behavior. BTW, it seems you're not sharing the code you're using for refreshing the page. – Mick Mnemonic Jan 01 '18 at 21:56
  • yes the alert is the issue , that is because i am calling the jsp page from inside the doPost method what i need to do is call another method and render the jsp page from there – uneeb meer Jan 01 '18 at 21:58
  • and my question is not even close of being duplicate as BalusC did! i amazed people dont even read the question before adding it as duplicate – uneeb meer Jan 01 '18 at 21:59
  • i amazed people dont even read the answer before complaining it being duplicate – BalusC Jan 01 '18 at 22:43
  • my base question is related to redirection! not get and post sir – uneeb meer Jan 01 '18 at 23:03
  • your base problem is related to misunderstanding get and post (and the duplicate shows how to properly use them, including performing a redirect), try **reading** the answer instead of only looking at code – BalusC Jan 02 '18 at 07:25

0 Answers0