Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

servlet programming problem in Eclipse

 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The code you posted a couple days ago shows only a doPost method, but not doGet. So a 405 is to be expected.
 
Kuladip Yadav
Ranch Hand
Posts: 162
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Kavitha Sen:
I tried running servlet..it says

405

Http method GET is not supported by this url


Which url are using to access html page ?
 
Kavitha Sen
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is my url kuldeep.

http://localhost/mySecondWebProject/form.html
[ August 20, 2008: Message edited by: Kavitha Sen ]
 
sharad sinha
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kavitha,
Please check your private message.
 
Sachin Joshi
Ranch Hand
Posts: 83
Java Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tomcat runs on port 8080 by default ....so try this url

http://localhost:8080/mySecondWebProject/form.html
 
Kavitha Sen
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Its working now. I can able to run in eclipse when i write code in html file. But when i wirte jsp i find some error. I am trying to solve by myself. If not i come here to ask you all.

Thankyou Sachin.

Special thanks to Sharad, he found exaclty where i was wrong.

Thanks to all Ranchers who try to help me solve the issue.

 
Lok Manick
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Kavitha...
Is it working fine now... any progress...
 
Kavitha Sen
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes Lok.

Its working fine. I learned to do it in IDE and Command prompt.


[ August 28, 2008: Message edited by: Kavitha Sen ]
 
roshan laddu
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
please tell me which java, Tomcat and Eclipse you are using? how you deployed Tomcat in eclipse? Also tell me path of java, Tomcat and Eclipse.
i have did all process at command prompt but following error when i am compiling java file:
MyFirstServlets.java:1: package javax.servlet does not exist
MyFirstServlets.java:2: package javax.servlet.http does not exist

i am using C:\Program Files\Java\jdk1.6.0_03
C:\Tomcat 5.5
D:\eclipse

thanking you,
 
Sachin Joshi
Ranch Hand
Posts: 83
Java Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to have Servlet API jar file in the CLASSPATH, Tomcat lib should have a servlet-api.jar file which you need to add to your CLASSPATH

Here is how you set the CLASSPATH

set CLASSPATH=%CLASSPATH%;C:\Tomcat 5.5\lib\servlet-api.jar

run this command every time you open a new command window to compile your code.
 
roshan laddu
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thankyou Sachin. Thankyou Kavitha. Now html is opening with following:

http://localhost:8080//mySecondWebProject/WebContent/form.html

***Note: i am doing all from commond prompt.
but when i select submit query i got following error:

HTTP Status 404 - //mySecondWebProject/WebContent/SelectBeer.do
-----------------------------------------------------------------------
type Status report
message //mySecondWebProject/WebContent/SelectBeer.do
description The requested resource (//mySecondWebProject/WebContent/SelectBeer.do) is not available.
------------------------------------------------------------------------
Apache Tomcat/6.0.18

My Paths are:

C:\Tomcat 6.0\webapps\mySecondWebProject\src\BeerSElect.java
C:\Tomcat 6.0\webapps\mySecondWebProject\WebContent\form.html
C:\Tomcat 6.0\webapps\mySecondWebProject\WebContent\WEB-INF
C:\Tomcat 6.0\webapps\mySecondWebProject\WebContent\WEB-INF\classes\BeerSelect.class
C:\Tomcat 6.0\webapps\mySecondWebProject\WebContent\WEB-INF\web.xml

and my codes are:

SelectBeer.java
---------------
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class BeerSelect extends HttpServlet{
public void doPost(HttpServletRequest request,HttpServletResponse response)throws IOException,ServletException{
response.setContentType("text/html");
PrintWriter out=response.getWriter();
out.println("Beer Selection Advice
");
String c= request.getParameter("color");
out.println("
Got beer color"+c);
}
}


web.xml
--------
- <web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4">
- <servlet>
<servlet-name>Ch3 Beer</servlet-name>
<servlet-class>BeerSelect</servlet-class>
</servlet>
- <servlet-mapping>
<servlet-name>Ch3 Beer</servlet-name>
<url-pattern>/SelectBeer.do</url-pattern>
</servlet-mapping>
</web-app>

please help me further.

Thank you,
 
Kavitha Sen
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Roshan,

Change Ch3 Beer instead of Ch3Beer in web.xml file. Try like this.

In IDE, after you configure tomcat with eclipse, Follow www.java-tips.org
[ August 29, 2008: Message edited by: Kavitha Sen ]
 
roshan laddu
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Kavitha.

Its working fine. I learned to do it on Command prompt.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic