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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T18:32:27+00:00 2026-05-16T18:32:27+00:00

I have a JSP page that has 2 forms running on Tomcat 6. One

  • 0

I have a JSP page that has 2 forms running on Tomcat 6. One is register form, Second is login form.
(please pay attention to context path, it’s going to kill me later)

(regis_and_login.jsp)

    <% String path = request.getContextPath(); %>

    //regis form
    <form id="regis_form" name="register_form" 
action="<%= path %>/servlet/process_register" method="post">

     //login form
    <form name="login_form" action="<%= path %>/servlet/login" method="POST">

GOAL

If insert statement to add new user fails, I want to redirect the user back to regis_and_login.jsp page with my custom error displayed.

servlet behavior

(login servlet)

If login fails, my custom error message is added to request (i.e. request.setAttribute("error", "there is error!") and dispatcher will forward back to the regis_and_login.jsp page and displays the error message properly but since this is forward, URL changes FROM http://localhost:8080/regis_and_login.jsp TO http://localhost:8080/servlet/login

(RegisterServlet)
Register servlet works same way. If any error is detected, I call setAttribute() on request and call RequestDispatcher’s forward function to redirect the user back to regis_and_login.jsp page with my custom error displayed.

PROBLEM

Each form works fine individually but when used together, it has some problem.

  1. Fill in invalid input to login form so you get redirected back to http://localhost:8080/servlet/login with my custom message properly showing up.

  2. On the same page (http://localhost:8080/servlet/login), fill in the registration form and submit.

Result:

Now the URL looks crazy.

The requested resource (/servlet/servlet/process_register) is not available.

My guess is this is because in regis_and_login.jsp, I set contextPath and concatenate to form’s action value: action="<%= path %>/servlet/process_register

So I believe after the URL is modified by forwarding (http://localhost:8080/servlet/login), contextPath is now set to “/servlet/” and that’s why I am requesting /servlet/servlet/process_register instead of just /servlet/process_register ?

There are few options in my mind:

  1. Just use absolute path to form’s action path

  2. Instead of forwarding, use response.sendRedirect(address) to stay away from URL change (but this disallow me to set attribute on request so I can’t display error message on my JSP page..this is against my goal)

Should I just use absolute path?

Please let me know if you need more clarification..

UPDATE

I asked help desk to remove mount directives and now it accepts all incoming request. The web.xml and form action URL no longer mentions “/servlet” and code started working just fine. Now I think the reason for having extra “/servlet”, I wonder if it is due to the mount directive..

  • 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-16T18:32:28+00:00Added an answer on May 16, 2026 at 6:32 pm

    but since this is forward, URL changes FROM http://localhost:8080/regis_and_login.jsp TO http://localhost:8080/servlet/login

    This phrase is a bit odd. A forward doesn’t change the URL at all. A forward just points to another resource (Servlet or JSP) to continue processing the current HTTP request. The URL change is caused because the form action URL is different from the original request URL. You’re firing a synchronous POST request on this URL. The URL in the browser address bar becomes the form action URL.

    Now the URL looks crazy.
    The requested resource (/servlet/servlet/process_register) is not available.

    So, in the beginning you have a context path of "/" and after submitting the form it becomes "/servlet"? Sorry, the problem is caused by something else. Is your webapplication deployed as ROOT? Are you running the code you think you’re running?


    However, I have two recommendations how to approach this issue differently:

    1. Don’t map the servlets on /servlet/process_register and /servlet/login but just on /process_register and /login.

      <form action="process_register" method="post">
      ...
      <form action="login" method="post">
      
    2. Or, hide the JSP file away in /WEB-INF folder, use a single servlet on /register_and_login for both GET and POST and let the servlet execute the desired action depending on the button pressed. This way the URL stays http://localhost:8080/register_and_login all the time.

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

Sidebar

Related Questions

I'm running tomcat and have some jsp pages that display a subset of a
I have a JSP page that needs to accept some info into a form,
I have a login.jsp page which contains a login form. Once logged in the
Right now I have a JSP page that allows to sort some items, when
I have a list of bean objects passed into my JSP page, and one
I have a JSP that is using Spring:form tags to bind controls to a
I have a JSP page where I load an arraylist which has the list
I have a JSP page that handles file downloads. I set the response header
I have a jsp page with two radio tags. The page contains a struts2
I have this simple Jsp page: <%@ page language=java import=java.awt.Color%> <% Color background =

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.