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

  • SEARCH
  • Home
  • 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 6723287
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:33:04+00:00 2026-05-26T09:33:04+00:00

Say I submit a simple page (that has no parameters, no forms, etc, and

  • 0

Say I submit a simple page (that has no parameters, no forms, etc, and I can’t add anything to this page), I end-up in the first servlet. Now I determine it’s time to do the stuff in the second servlet. The second servlet expects a bunch of parameters and form fields populated, so first I’d need to set those up in the first servlet, then figure out how to get those things to the second servlet. When I tried to add something to the parameter map, it errored-out with “no modifications are allowed to a locked parameter map” (which is the way JSP is supposed to work). I was thinking maybe I should instantiate up another request object, but I’m not sure how to do that (and keep myself out of hot water). If, in the first servlet, I ever am able to construct a request object with all “the right stuff”, then I’d need to run that second servlet with that request, and let it take me to whatever page the second servlet redirects me to. I think that one would just be a response.sendRedirect();

How do I get additional parameters and things defined in the first servlet so when I do the sendRedirect, the second servlet has everything it needs?

  • 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-26T09:33:05+00:00Added an answer on May 26, 2026 at 9:33 am

    The normal approach to invoke other servlet would be to use RequestDispatcher#include().

    request.getRequestDispatcher("/secondServletURL").include(request, response);
    

    If you’d like to add extra request parameters and you would like to end up with them in the (bookmarkable!) URL of redirected page, then you have to populate a query string based on those parameters yourself before redirecting.

    response.sendRedirect(request.getContextPath() + "/secondServletURL?" + queryString);
    

    You could create the query string as follows:

    Map<String, String[]> params = new HashMap<String, String[]>(request.getParameterMap());
    params.put("name1", new String[] {"value1"});
    params.put("name2", new String[] {"value2"});
    // ...
    
    String queryString = toQueryString(params);
    

    where toQueryString() look like follows:

    public static String toQueryString(Map<String, String[]> params) {
        StringBuilder queryString = new StringBuilder();
    
        for (Entry<String, String[]> param : params.entrySet()) {
            for (String value : param.getValue()) {
                if (queryString.length() > 0) {
                    queryString.append("&amp;");
                }
    
                queryString
                    .append(URLEncoder.encode(param.getKey(), "UTF-8"))
                    .append("=")
                    .append(URLEncoder.encode(value, "UTF-8"));
            }
        }
    
        return queryString.toString();
    }
    

    However, as that servlet seems to be running in the same container and you’d like to reuse the second servlet’s logic without exposing the additional parameters into public, then likely a much better way is to refactor the business code of that tight coupled second servlet into another, separate and reuseable class which you finally just import and call in your both servlets. You can then pass the data to that class using a reuseable Javabean object.

    For example, servlet 1:

    SomeData data = new SomeData();
    data.setSomeProperty1(request.getParameter("someProperty1"));
    data.setSomeProperty2("some custom value");
    data.setSomeProperty3("some other custom value");
    
    SomeBusinessService service = new SomeBusinessService();
    service.doSomeAction(data);
    

    And servlet 2:

    SomeData data = new SomeData();
    data.setSomeProperty1(request.getParameter("someProperty1"));
    data.setSomeProperty2(request.getParameter("someProperty2"));
    data.setSomeProperty3(request.getParameter("someProperty3"));
    
    SomeBusinessService service = new SomeBusinessService();
    service.doSomeAction(data);
    

    The SomeBusinessService is usually to be an EJB.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say I have this simple form: class ContactForm(forms.Form): first_name = forms.CharField(required=True) last_name = forms.CharField(required=True)
I think this should be simple. Say I've got the following jQuery: $someForm.live('submit', function(event)
Say that I have simple command line application, that looks something like this #
I know this must be a relatively simple problem, but Google has failed me.
Let's say that I have a file (file1.php) with a simple form with the
I am new to php, I can do a simple login page, e.g create
I'm trying to write a simple script that effectively fades out the page content,
Say that I have the Python code: someString = file(filename.jpg).read() How can I replicate
Lets say I have a really simple html form: <form action=./whatever.php method=POST> <input type=submit
Say I have textboxes, dropdownlists and submit buttons. They are all inline-elements. Which means

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.