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 3223388
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T16:06:05+00:00 2026-05-17T16:06:05+00:00

If I leave the action attribute out of my form so it posts back

  • 0

If I leave the action attribute out of my form so it posts back to the same JSP I have no trouble reading the request parameters. However when I add an action attribute to handle the form with a separate JSP, the request parameters are null. Here’s a short example (FormTest.jsp) that illustrates how I’m reading the request.

<HTML>
    <HEAD>
        <TITLE>FormTest.jsp</TITLE>
    </HEAD>
    <BODY>
        <H3>Using a Single Form</H3>
        <%
            String command = request.getParameter("submit");
        %>
            You clicked <%= command %>

        <FORM NAME="form1" METHOD="POST">
            <INPUT TYPE="SUBMIT" NAME="submit" VALUE="First">
            <INPUT TYPE="SUBMIT" NAME="submit" VALUE="Second">
            <INPUT TYPE="SUBMIT" NAME="submit" VALUE="Third">
        </FORM>
    </BODY>
</HTML>

The above page works as expected. Initially the page prints You clicked null along with the form. Clicking any of the three buttons changes the message to You clicked First, etc.

Now I change just one line in the page above to add the action attribute:

<FORM NAME="form1" METHOD="POST" ACTION="FormHandler.jsp">

I added a separate JSP to my project to read the request parameter as follows:

<HTML>
    <HEAD>
        <TITLE>FormHandler.jsp</TITLE>
    </HEAD>
    <BODY>
        <H3>Form Handler</H3>
        <%
            String command = request.getParameter("submit");
        %>
            You clicked <%= command %>
    </BODY>
</HTML>

I expected the new FormHandler.jsp to just print out which button was pressed on the other page, but it seems the request parameter is always null.

What could be interfering with the request parameters being sent to a separate JSP?

Update:

This project has a JSF configuration file as well. I changed the action attribute to ACTION="FormHandler.faces" and the code above works but I don’t quite understand why yet. Here’s the method that’s redirecting requests that end in .jsp.

public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
        throws ServletException, IOException {
    HttpServletRequest request = (HttpServletRequest) req;
    HttpServletResponse response = (HttpServletResponse) res;
    String uri = request.getRequestURI();

    if (uri.endsWith(".jsp")) {
        int length = uri.length();
        String newAddress = uri.substring(0, length - 3) + ".faces";
        response.sendRedirect(newAddress);
    }
    else { //Address ended in "/"
        response.sendRedirect("login.faces");
    }
}

Now I guess I need to know 1) how to figure out if this is the source of the problem, and 2) is there a way to preserve the request parameters when the response is redirected?

There’s also an entry in the web.xml configuration file for this project that sets a filter mapping.

<filter-mapping>
    <filter-name>faces-redirect-filter</filter-name>
    <url-pattern>*.jsp</url-pattern>
</filter-mapping>

I suppose (but it’s probably clear by now that I’m new to JSF, so someone correct me if I’m wrong) that using the .faces extension in my action attribute bypasses this filter.

  • 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-17T16:06:06+00:00Added an answer on May 17, 2026 at 4:06 pm

    POST parameters are lost because sendRedirect() sends a 302 Moved Temporarily redirect, which instructs the browser to load the specified page with GET request.

    To retain parameters you need to use 307 Temporary Redirect instead – it instructs the browser to repeat a POST request to the specifed URI:

    response.setHeader("Location", newAddress); 
    response.setStatus(HttpServletResponse.SC_TEMPORARY_REDIRECT); 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am developing a Leave of Absence Request Form for a client. The form
On my application when I back out of the menu screen to leave the
You could very well leave out as a technical lead, but I think it
We had an employee leave the company, and they left some files checked out
I have to leave in a DataTable only records with dates currently not present
Possible Duplicate: How important is it to leave out the last ';' inside a
I have an issue that when I leave the android device idle for a
I have an html link that has uses hover() (well, the hoverIntent plugin...but same
I have a simple Log model, that records the fact of calling controller's action.
I need to execute an action of a controller when a user leave a

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.