problem when using servlet and web project with java
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 开发者_StackOverflowgetting 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.
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..
The URL should be http://localhost:8080/ServletProject/Main.html
. Where ServletProject
is your application context.
精彩评论