• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Merlin Thomas
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you can alos use relative paths in your action attribute like this
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64623
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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"
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic