File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Error 404 : Calling Servlet through Html Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Error 404 : Calling Servlet through Html " Watch "Error 404 : Calling Servlet through Html " New topic
Author

Error 404 : Calling Servlet through Html

Rashid Ali
Ranch Hand

Joined: Jan 16, 2001
Posts: 349
My Servlet encountered an error 404 while lounches.
I have also set the desired field in Acces file and made its connection using jdbc/odbc connection properly.
Please note that i am using tomcat 3.x with J2SDK13.
Following is the code of both .html and servlet file:


Please help me to sort out the above problem.
Thank you very much in advance.
[ February 03, 2002: Message edited by: Rashid Ali ]
Arun Boraiah
Ranch Hand

Joined: Nov 28, 2001
Posts: 233
hi,
It would be better, if question are short and sweet. Try to put the question rather the source code.
coming to the problem you are facing. Try following things.
1)'http://localhost:8080/examples/servlet/GuestBookServlet' call this servlet directly through browser.(if servlet don't get called
then the problem in servlet reg)
2)If this servlet is not been getting calledmeans server not finding the servlet). Then place this servlet in the folder >tomcat root>\webapps\examples\web-inf\classes folder .
(it is good pratice to reg this servlet in web.xml but for your case it is optional).
and then repeat the step one. Once if it get called by browser. It should work even when you call through html page.
-arun


Sharing is learning
Rashid Ali
Ranch Hand

Joined: Jan 16, 2001
Posts: 349
Thank you very much Arun for your quick reply.
I will try to only put desired question straightfully in future.
Now when i directly run the Servlet without html file it shows the following error:

Apache Tomcat/4.0.1 - HTTP Status 405 - HTTP method GET is not supported by this URL
-------------------------------------------
type Status report
message HTTP method GET is not supported by this URL
description The specified HTTP method is not allowed for the requested resource (HTTP method GET is not supported by this URL).

Since i do not need the get request and only place the doPost() instead - it shows the above error that needs the doGet() method.
Please suggest as i am a beginner in servlet programming.
Thanks again for your kind suggestion.
Rashid Ali
Rashid Ali
Ranch Hand

Joined: Jan 16, 2001
Posts: 349
I understand that when we put url on browser it looks in the servlet the doGet() method and if it does not find it throws the above exception.
But how can i do the doPost() method run as i only need of that.
Best regards
Rashid Ali
Arun Boraiah
Ranch Hand

Joined: Nov 28, 2001
Posts: 233
hi,
You can use call doPost from with in doGet method,
else use service method to test.
But one more thing if 405 error is displayed means your servlet is found to the web server.
Now since your server is calling servlet. Do one more test. Regester your servlet in web.xml and restart and try.
All the best
-arun
[ February 04, 2002: Message edited by: arun boraiah ]
Rashid Ali
Ranch Hand

Joined: Jan 16, 2001
Posts: 349
Thanks Arun, you are so kind.
After puting the following doGet() in my servlet:

I get the following error on my browser

Apache Tomcat/4.0.1 - HTTP Status 500 - Internal Server Error
---------------------------------------------
type Exception report
message Internal Server Error
description The server encountered an internal error (Internal Server Error) that prevented it from fulfilling this request.
exception
java.lang.NullPointerException
at GuestBookServlet.doPost(GuestBookServlet.java:60)
at GuestBookServlet.doGet(GuestBookServlet.java:41)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
etc
etc


I think 505 is a servlet internal error and it properly connects with servlet but shows the NullPointerException which means now i should to send the parameters through .html file to store it to DB through servlet?
Am i right.
Please revert with your kind suggestions?
Thanks very much.
Rashid Ali
[ February 04, 2002: Message edited by: Rashid Ali ]
Arun Boraiah
Ranch Hand

Joined: Nov 28, 2001
Posts: 233
hi,
This means that there is no problem of your servlet getting called. Since nullpointer exception is throwen check your code at line 60. Find out which object is not reciving value. Put some debug statement. Find out what is the actual problem. (I think since you are calling servlet directly some parameter are not passed due to which nullpointer exception is thrown)
-arun
Rashid Ali
Ranch Hand

Joined: Jan 16, 2001
Posts: 349
So kind of you to reply me too promptly, just let me check and then i shall let you know the result.
Thank you very much Arun.
Rashid Ali
Rashid Ali
Ranch Hand

Joined: Jan 16, 2001
Posts: 349
Again bothering you for just a little problem:
Now my above application works fine and stores the value through .html file but it just stores the null values instead of text parameters passed through html file. These null values get also stored in database.
Please also let me know who can i register my servlet file with web.xml file as suggested above.
Kindly advise how can i overcome with these problems.
Rashid Ali
[ February 04, 2002: Message edited by: Rashid Ali ]
Beksy Kurian
Ranch Hand

Joined: Jul 11, 2001
Posts: 254
In your request.getParameter, give the names exactly like you have it in the html file.
For eg: "email"
"firstName"
"lastName"
"company" etc
Hope it helps
Beksy
[ February 04, 2002: Message edited by: Beksy Kurian ]
Arun Boraiah
Ranch Hand

Joined: Nov 28, 2001
Posts: 233
hi,
Check this out.
in your servlet you have mentioned request.getParameter("Email");
but in your html you have given the name has email.(cases of name is different). Check for other fields also.
This might be the cause. Check this out.
Regarding servlet reg open your web.xml in text editor present in your context (present in web-inf folder).Find the servlet tag (sample given below)
<servlet>
<servlet-name>
some servlet name
</servlet-name>
<servlet-class>
some servlet class name
</servlet-class>
</servlet>
Make one more copy. Then in place of servlet name give the name by which you want to call the servlet. in place of servlet class name give the actual servlet class name(if it present in package give complete package + class name separated by dot).
So your servlet will look like this.
<servlet>
<servlet-name>
GuestBookServlet
</servlet-name>
<servlet-class>
GuestBookServlet
</servlet-class>
</servlet>
-arun
[ February 04, 2002: Message edited by: arun boraiah ]
Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

Beksy is right, the case is very important.

Regarding web.xml, you will need a mapping as well.


So there is a level of indirection. In your HTML form's action attribute you will simply need to put "/guestbook" (the url-pattern part of servlet-mapping). This maps to the GBServlet, which is then looked up in the servlet tag... and GB Servlet is implemented by GuestBookServlet class.
[ February 05, 2002: Message edited by: Mike Curwen ]
Rashid Ali
Ranch Hand

Joined: Jan 16, 2001
Posts: 349
Thank you very much to all of you for replying to my querries which solved my all problems easily.
Specially to Arun who promptly responded to my querries for which i am really gratful to him.
Now my 3-tier application runs efficiently without any problem.
Thank you all once again.
Keep it up please.
Rashid Ali
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Error 404 : Calling Servlet through Html
 
Similar Threads
please observe this snippet
java.util.Enumeration
javax. servlet.Servlet Exception: Initialization failed, Unable to get DB connection
database best practice
Enumeration