Help understanding servlet mapping so JSP form action works properly

I am trying to learn JSP and Java Servlets.  Tomcat is set up such that all of my files have to go into a subdirectory under the WEBAPPS directory.  

    webapps\kr

My application is a simple user registration program.

Here's what it looks like under the kr directory:

index.html
images\xxx.jpg
hw5\register.jsp
hw5\compute.jsp
WEB-INF\classes\hw5\register.class
WEB-INF\classes\hw5\updateRegistration.class

So here's my problem.  I start off the app in the index.html.  From there I select an option that takes me to form1.jsp.  I enter some data and hit submit.
Here's my form action
    <form action="../register" method="get">

This works fine the first time.

So then from the second page, I decide I want to edit something on the first page.  So I select Edit:

    <form action="updateRegistration" method="POST">
        <input type="hidden" name="actn" value="Edit">
        <input type="submit" value="Edit"/>
    </form>


This takes me to a servlet which does nothing more than send me back to the first page

        if(action.equals("Edit"))
        {
            url = "/hw5/conference.jsp";
        }

        RequestDispatcher dispatcher =
             getServletContext().getRequestDispatcher(url);
        dispatcher.forward(request, response);


So now I'm back on the first page and I make my change and then I click submit.  But this time I get a 404 error, "...the requested resource (/register) is not available

Please help me understand what I'm doing wrong, this is driving me nuts!!!

Here's a snippet from my web.xml file

    <servlet>
        <servlet-name>register</servlet-name>
        <servlet-class>hw5.register</servlet-class>
    </servlet>
    <servlet>
        <servlet-name>updateRegistration</servlet-name>
        <servlet-class>hw5.updateRegistration</servlet-class>
    </servlet>

Thanks!
Karen




kreid1960Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

objectsCommented:
>     <form action="../register" method="get">

suggest not using relative url and instead specify the absolute url
0
kreid1960Author Commented:
So what would my absolute url be?
0
objectsCommented:
sounds like its /hw5/register
0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

kreid1960Author Commented:
I'm trying it.  You may be right!
0
kreid1960Author Commented:
Nope.  I get the 404 error with that.  I tried /krroot/hw5/register too and it also failed.

This is what is driving me crazy, I can't figure out what the url should be.
0
objectsCommented:
what mapping do you have in your web.xml
0
kreid1960Author Commented:
I put it in the original post:

    <servlet>
        <servlet-name>register</servlet-name>
        <servlet-class>hw5.register</servlet-class>
    </servlet>
    <servlet>
        <servlet-name>updateRegistration</servlet-name>
        <servlet-class>hw5.updateRegistration</servlet-class>
    </servlet>

0
objectsCommented:
that just defines the servlet, you also need to specify the mapping eg.


   register
   /register


0
kreid1960Author Commented:
Yes, I have that too.  Sorry I forgot to post it.

    <servlet-mapping>
        <servlet-name>register</servlet-name>
        <url-pattern>/register</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>updateRegistration</servlet-name>
        <url-pattern>/updateRegistration</url-pattern>
    </servlet-mapping>
0
objectsCommented:
> sounds like its /hw5/register

sorry, ignore that. Should be

 /kr/register

got your package name and context name mixed up
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
kreid1960Author Commented:
Perfect!  It worked.

Thank you!!
Karen
0
kreid1960Author Commented:
I wish I had asked weeks ago.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java App Servers

From novice to tech pro — start learning today.