1

i have just started using servlet. basically i am new to web projects. I am using eclipse as development IDE. In that i have created a dynamic web project, in the same i added one html page viz Main.html with the following sript:_

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Main page</title>
</head>
<body>
<b>this is the first page</b>
</body>
</html>

and following is my web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4" 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 http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
    <display-name>ServletProject</display-name>
    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
        <welcome-file>index.htm</welcome-file>
        <welcome-file>index.jsp</welcome-file>
        <welcome-file>default.html</welcome-file>
        <welcome-file>default.htm</welcome-file>
        <welcome-file>default.jsp</welcome-file>
    </welcome-file-list>
</web-app>

i am using tomcat 6.0 as web container, in eclipse only i have integrated tomcat and have added the web project in it. The server is getting started properly. When i am trying to access the Main.html page, i am not getting anything on the browser, in the tomcat server configuration, there are two ports, one is admin port and other is HTML/1.1 port and value is 8005 and 8080 respectively. When i am using http://localhost:8005/Main.html i am getting nothing one the web browser, but when i use http://localhost:8080/Main.html i get some tomcat error.

is there something i am missing. I am unable to figure it out. Please help me.

2
  • Can you share the error code/error details as well? Commented Nov 12, 2010 at 6:29
  • @Faisal : i get some HTTP Status 404 error when i use the second URL as mentioned above Commented Nov 12, 2010 at 6:54

2 Answers 2

3

Edit: Ah yeah, you need to use the ServletProject as url-pattern.. Try to access the file with the following URL: http://localhost:8080/ServletProject/Main.html

You need to configure your application properly in the web.xml file and if you want to use later a Java class and use it as a Servlet you have to define this in the web.xml like that:

<servlet> 
   <servlet-name>CurrencyConverter</servlet-name> 
   <servlet-class>servlets.Converter</servlet-class>
</servlet> 
<servlet-mapping>
   <servlet-name>CurrencyConverter</servlet-name>
   <url-pattern>/convert</url-pattern>
</servlet-mapping>

The url pattern defines the path you can access it later. To access the CurrencyConverter in the above code you need to use this url: http://localhost:8080/convert

Yeah and it would be good when you could show us the error you get..

Sign up to request clarification or add additional context in comments.

Comments

2

The URL should be http://localhost:8080/ServletProject/Main.html. Where ServletProject is your application context.

5 Comments

ah u beat me to it, but if he had chosen "Right Click > Run As > Run on Server" within Eclipse - it would have opened the browser with the right URL and worked.
@JoseK: Yeah. But I am not very familiar with Eclipse. BTW, where is my upvote ;).
dude, you beat me to the answer, and you want me to reward you for it :) the OP hasnt confirmed this worked yet, hmmm
@JoseK: Okay! that means you were not sure of your answer, that might made you late ;)
Nope - I was composing some theory on how "ServletProject" seemed to be the web app context auto-populated by Eclipse into web.xml on creating the project. Thats when I saw the new answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.