• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

form's action attribute

 
Noopur Kore
Ranch Hand
Posts: 77
Java Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What path should I give in the action attribute of form tag?
1. If I want to hard code it
2. How to go about it using web.xml?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65229
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The form action should be the context path, followed by the servlet mapping. The deployment descriptor (web.xml) is where you create the mapping for the servlet.

You should never hard-code the context path.
 
Noopur Kore
Ranch Hand
Posts: 77
Java Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
context path?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65229
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are going to be working with servlets, you need to learn basic concepts. I'd suggest reading the Spec.

Or at least start with: servlet context path
 
Noopur Kore
Ranch Hand
Posts: 77
Java Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
actually the problem is..
I'm getting an 404 error on URL -- http://localhost:8084/InstrumentLayout/JSP/login.jsp

here, InstrumentLayout is my webapp.
And here, is my form action, <form name="loginform" method="post" action="/InstrumentLayout/login" >

and here is my web.xml

<servlet-mapping>
<servlet-name>LoginServlet</servlet-name>
<url-pattern>/login</url-pattern>
</servlet-mapping>

Where am I going wrong?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65229
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the relationship of the JSP to the servlet? Is it being forwarder to? Redirected? We need the details.
 
sneha ulhe
Ranch Hand
Posts: 52
Eclipse IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try simply /login as action.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65229
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sneha ulhe wrote:try simply /login as action.

Bad advice. Very bad. That assumes that the context path is "/", which only true when the web app is deployed a certain way, and is not correct to assume.
 
sneha ulhe
Ranch Hand
Posts: 52
Eclipse IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
but in web.xml he has passed URL pattern /login.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65229
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It still must be prefixed with the context path. Otherwise how would the container know which web app the request is intended for?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic