aspose file tools*
The moose likes Servlets and the fly likes Problem with URL paths (absolute and relative) in case of Servlets Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Problem with URL paths (absolute and relative) in case of Servlets" Watch "Problem with URL paths (absolute and relative) in case of Servlets" New topic
Author

Problem with URL paths (absolute and relative) in case of Servlets

Merlin Thomas
Greenhorn

Joined: Jul 15, 2011
Posts: 6
Hello,

I am very confused regardind the URL pattern we specify in web.xml, and the path we specify in an HTML Form

this my web.xml
<web-app>
<servlet>
<servlet-name>xxx</servlet-name>
<servlet-class>ParamServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>xxx</servlet-name>
<url-pattern>MyLogin</url-pattern>
</servlet-mapping>
</web-app>
-----------------------------------------------------------------------------------------------
and this is my Login.html
1<html>
2<body>
3 <h1>Login Page</h1>
4 <form method="get" action="MyLogin">
5


6username : <input type="text" name="username">

7password : <input type="text" name="password">
8<input type="submit" value="LOGIN">
9


10 </form>
11</body>
12</html>

so if i change line 4 to <form method="get" action="/MyLogin">, i am getting a Page Not found Error, Why is this happening?
/MyLogin means the absolute path of the webapp right?

please help


thanks
elvadas nono
Greenhorn

Joined: Jul 04, 2011
Posts: 12
hi Guy, your url-pattern is wrong in the DD
you should use this <,
instead of <url-pattern>MyLogin</url-pattern> see the slash for context Path
elvadas nono
Greenhorn

Joined: Jul 04, 2011
Posts: 12
you can alos use relative paths in your action attribute like this
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61433
    
  67

elvadas nono wrote:you can alos use relative paths in your action attribute like this

No.
Do not. This is a recipe for disaster.

URLs paths to resources in the same app should always be server-relative and start with the context path.

For example: action="${pageContext.request.contextPath}/servletPath"


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem with URL paths (absolute and relative) in case of Servlets