开发者

Customize <url-pattern> to link a Form to a FormAction

First, I am a newbie in Java/J2EE development. So, please be indulgent with my leak of vocabulary (but feel free to correct me ;)

  • Here is my first problem :

I built a first form (named form1) in a .jsp page :

<form name="form1" action="formaction1.do" method="get">

I redirect the result of my form to a FormAction1 java class :

<servlet>
    <servlet-class>com.servlet.myproject.FormAction1</servlet-class>
    <servlet-name>FormAction1</servlet-name>
</servlet>
<servlet-mapping>
    <servlet-name>FormAction1</servlet-name>
    <url-pattern>*.do</url-pattern>
</servlet-mapping>

Here is my FormAction1 java class :

public class FormAction1 extends HttpServlet
{
    public void doGet(HttpServletRequest request, HttpServletResponse response)
    throws IOException, ServletException
    {
        request.getRequestDispatcher("formaction1.jsp").forward(request, response);     
    }

    public void doPost(HttpServletRequest request, HttpServletResponse response)
    throws IOException, ServletException
    {
        doGet(request, response);
    }

}

This is working fine.

Now, I'd like to create another form, named form2, and link it to FormAction2.

However, FormAction1 receives every .do request !

I tried to customize my <url-pattern> by writing :

<url-pattern>formaction1.do</url-pattern>

I guess it would've been too easy :D

Tomcat doesn't like it : I get a 404 error on every page of my project.

So, do you have any solution ?

  • Just a bonus question :

What's the point to use a class like FormAction1, rewrite doGet method, while I can just write :

<form name="form1" action="anotherFile.jsp" method="get">

and recov开发者_开发百科er infos with a request.getParameter() in anotherFile.jsp ?


doesn't url-pattern requires a match starting from the beginning, in that case

<url-pattern>/formaction1.do</url-pattern>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜