This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes IDEs, Version Control and other tools and the fly likes servlet programming problem in Eclipse Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » IDEs, Version Control and other tools
Bookmark "servlet programming problem in Eclipse" Watch "servlet programming problem in Eclipse" New topic
Author

servlet programming problem in Eclipse

Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41148
    
  45
The code you posted a couple days ago shows only a doPost method, but not doGet. So a 405 is to be expected.


Ping & DNS - my free Android networking tools app
Kuladip Yadav
Ranch Hand

Joined: Jul 30, 2008
Posts: 162

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

Joined: May 15, 2008
Posts: 28
This is my url kuldeep.

http://localhost/mySecondWebProject/form.html
[ August 20, 2008: Message edited by: Kavitha Sen ]
sharad sinha
Greenhorn

Joined: Jul 13, 2008
Posts: 26
Kavitha,
Please check your private message.


Thanks, Sharad<br />SCJP 5 (July, 2008)
Sachin Joshi
Ranch Hand

Joined: Aug 06, 2008
Posts: 83

Tomcat runs on port 8080 by default ....so try this url

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


Web Development Tips and Tutorials - By Sachin
Kavitha Sen
Greenhorn

Joined: May 15, 2008
Posts: 28
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

Joined: Jan 24, 2005
Posts: 71
Hi Kavitha...
Is it working fine now... any progress...


with regards,
Loks (SCJP, SCWCD)
Kavitha Sen
Greenhorn

Joined: May 15, 2008
Posts: 28
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

Joined: Aug 27, 2008
Posts: 9
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

Joined: Aug 06, 2008
Posts: 83

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

Joined: Aug 27, 2008
Posts: 9
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

Joined: May 15, 2008
Posts: 28
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

Joined: Aug 27, 2008
Posts: 9
Thank you Kavitha.

Its working fine. I learned to do it on Command prompt.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: servlet programming problem in Eclipse
 
Similar Threads
Servlet Doesn't appear to be working.
Starting out on Servlets - from Head First Servlets and JSP
Headfirst ch3 Beerselect submit button not working
Problem getting the Beer Selection Page screen shot
servlet Not able to fetch value from html file