Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7541251
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T07:50:40+00:00 2026-05-30T07:50:40+00:00

I got a problem with 2 servlets. Basically I got 1 jsp page with

  • 0

I got a problem with 2 servlets. Basically I got 1 jsp page with form, when I click on submit, i need to get all variables from this jps, in order to inject them into the second on (input type=”hidden”), for finally submit all together.

My servlet 1 (Add client)

    @Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    System.out.println("salut 1  ");
    request.getRequestDispatcher("/JSP/Template/BankAdvisor/AddClient.jsp").forward(request, response);
}

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

    String firstname = request.getParameter("firstname");
    String lastname = request.getParameter("lastname");
    String email = request.getParameter("email");
    String address = request.getParameter("address");
    String city = request.getParameter("city");
    String zipcode = request.getParameter("zipcode");
    String phone = request.getParameter("phone");

    if (firstname != null && lastname != null && email != null && address != null && city != null && zipcode != null && phone != null) {

        if (!lastname.isEmpty() && !firstname.isEmpty() && !email.isEmpty() && !address.isEmpty() && !city.isEmpty() && !zipcode.isEmpty() && !phone.isEmpty()) {

            request.setAttribute("firstname", firstname);
            request.setAttribute("lastname", lastname);
            request.setAttribute("email", email);
            request.setAttribute("address", address);
            request.setAttribute("city", city);
            request.setAttribute("zipcode", zipcode);
            request.setAttribute("phone", phone);
            request.getRequestDispatcher("/BankAdvisor/AddAccount").forward(request, response);

        } else {

            response.sendRedirect(getServletContext().getContextPath() + "/BankAdvisor/AddClient");
        }

    } else {

        response.sendRedirect(getServletContext().getContextPath() + "/BankAdvisor/AddClient");
    }

}

My servlet 2 (Add account)

    protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    request.getRequestDispatcher("/JSP/Template/BankAdvisor/AddAccount.jsp").forward(request, response);
    String firstname = request.getParameter("firstname");
    String lastname = request.getParameter("lastname");
    String email = request.getParameter("email");
    String address = request.getParameter("address");
    String city = request.getParameter("city");
    String zipcode = request.getParameter("zipcode");
    String phone = request.getParameter("phone");
}

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

    String firstname = request.getParameter("firstname");
    String lastname = request.getParameter("lastname");
    String email = request.getParameter("email");
    String address = request.getParameter("address");
    String city = request.getParameter("city");
    String zipcode = request.getParameter("zipcode");
    String phone = request.getParameter("phone");

    //The two news variables
    String accountName = request.getParameter("accountname");
    String accountType = request.getParameter("accounttype");

    if (firstname != null && lastname != null && email != null && address != null && city != null && zipcode != null && phone != null) {

        if (!lastname.isEmpty() && !firstname.isEmpty() && !email.isEmpty() && !address.isEmpty() && !city.isEmpty() && !zipcode.isEmpty() && !phone.isEmpty()) {

         // ACTION 
        } else {
            response.sendRedirect(getServletContext().getContextPath() + "/BankAdvisor/AddClient");
        }

   } else {
 response.sendRedirect(getServletContext().getContextPath() + "/BankAdvisor/AddClient");
   }
}

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T07:50:42+00:00Added an answer on May 30, 2026 at 7:50 am

    In servlet 1 you should use :

    getServletContext().getRequestDispatcher("/BankAdvisor/AddAccount").forward(request, response);
    

    instead of :

    request.getRequestDispatcher("/BankAdvisor/AddAccount").forward(request, response);
    

    because with ServletRequest#getRequestDispatcher(java.lang.String), if the path begins with a “/” it is interpreted as relative to the current context root (i.e. context path of the current request).

    • Example : if you received a request on http://test/myapp/toto it will forward on http://test/myapp/toto/BankAdvisor/AddAccount

    Whereas with ServletContext#getRequestDispatcher(java.lang.String) path is interpreted as relative to the current context root (i.e. context path of the current web application).

    • Example : if you received a request on http://test/myapp/toto it will forward on http://test/myapp/BankAdvisor/AddAccount if the webapp context root is http://test/myapp
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I got a problem with this linq query: from PersistedFileInfo fi in m_Database from
I want to redirect JSP page from one servlet. All JSP pages are under
I got a problem like this (this is html/css menu): Eshop | Another eshop
I got a problem today. It had a method and I need to find
We got a problem with NUnit 2.5.3: nunit-console.exe does not return after finishing all
I've got a problem with the authentication features of Servlet 3.0: With this code
We've got a weird problem while migrating our app from 1.3.7 to 2.0.0. Our
In my Struts form I've got a list. In a JSP I iterate over
Suddenly my app started raising DeadlineExceededException from all servlets/tasks. I also noticed that on
I've got a problem with our live server. Occasionally a page will not load,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.