Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem in form action tag

 
Lala Asif Allana
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can any one tell me how to put servlet path in tomcat 5 in html form action tag when calling that servlet by submit action.
i m writing like this <form action="/loginservlet" method=POST> but it is not working as class file is in the classes folder.
Asif.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64827
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What mapping did you specify in the deployment descriptor?
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Lala Asif Allana:
...
i m writing like this <form action="/loginservlet" method=POST>
Asif.


First, as Bear has asked, show us what you're using for a mapping in your deployment descriptor.

One you have a mapping that you know works (test by typing the URL into your browser's address window) then test your form action attribute.

I can say that building a relative link the way that you did is almost always wrong for a Java Web App. Your link will only work if your app is the default or root app in your container. Either make your link completely relative by removing the preceding slash (also not the best way) or, read the context path from the request object to build your link so that it is relative to the root of your web application.

Example:



Or if you're not using a JSP 2.0 compliant container:
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic