File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes problem in form action tag Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "problem in form action tag" Watch "problem in form action tag" New topic

problem in form action tag

Lala Asif Allana

Joined: Jun 16, 2007
Posts: 5
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.
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63858

What mapping did you specify in the deployment descriptor?

[Asking smart questions] [About Bear] [Books by Bear]
Ben Souther

Joined: Dec 11, 2004
Posts: 13410

Originally posted by Lala Asif Allana:
i m writing like this <form action="/loginservlet" method=POST>

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.


Or if you're not using a JSP 2.0 compliant container:

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
I agree. Here's the link:
subject: problem in form action tag
It's not a secret anymore!