0

I have a couple of webpage inside a folder within webpages, i tried RequestDispatcher but the page is not rendering

I have a folder named "admin" inside webpages in java web application

I have 2 jsp inside admin, page1 and page2.

When use clicks submit button in page1, it goes to servlet and from servlet to page2

But this is not happening...

folder inside webpages - admin

page1.jsp

<form action="pagecheck">
        <input type="submit" value="page" name="page">
</form>

pagecheck.java (Servlet)

if(request.getParameter("page")!=null)
        {
          RequestDispatcher rd=request.getRequestDispatcher("/web/admin/page2.jsp");
          rd.forward(request, response);
        }

page2. jsp

<h1> Success </h1>

When i run this and click submit in page1, the next thing i see is HTTP Status 404: Not found

JavaLearner1
  • 607
  • 2
  • 8
  • 21

2 Answers2

0

Try this code.

   if(request.getParameter("page")!=null)
            {
              RequestDispatcher rd=request.getRequestDispatcher("admin/page2.jsp");
              rd.forward(request, response);
            }
M S Parmar
  • 955
  • 8
  • 22
0

I feel this 404 is coming for your servlet.Since it is trying to find servlet in admin folder.You need to fix that first.If you are using annotations,then you can change

@WebServlet("/admin/pagecheck")

Then you will need to modify your servlet code also like this

if(request.getParameter("page")!=null)
            {
              RequestDispatcher rd=request.getRequestDispatcher("page2.jsp");
              rd.forward(request, response);
            }

This should work.

RockAndRoll
  • 2,247
  • 2
  • 16
  • 35