简体   繁体   English

Java使用Servlet和Web项目时出现问题

[英]problem when using servlet and web project with java

i have just started using servlet. 我刚刚开始使用servlet。 basically i am new to web projects. 基本上,我是Web项目的新手。 I am using eclipse as development IDE. 我正在使用eclipse作为开发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:_ 为此,我创建了一个动态Web项目,在同一项目中,我添加了一个html页面,即Main.html,带有以下代码:_

<!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 以下是我的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. 我正在使用tomcat 6.0作为Web容器,仅在Eclipse中,我已经集成了tomcat并在其中添加了Web项目。 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. 当我尝试访问Main.html页面时,浏览器上没有任何内容,在tomcat服务器配置中,有两个端口,一个是admin端口,另一个是HTML / 1.1端口,值分别是8005和8080 。 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. 当我使用http://localhost:8005/Main.html时,Web浏览器什么都没有得到,但是当我使用http://localhost:8080/Main.html我得到了一些tomcat错误。

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 编辑:是的,您需要使用ServletProject作为url-pattern。尝试使用以下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: 您需要在web.xml文件中正确配置您的应用程序,如果您以后要使用Java类并将其用作Servlet,则必须在web.xml中进行如下定义:

<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 要在上面的代码中访问CurrencyConverter,您需要使用以下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 . 该URL应该是http://localhost:8080/ServletProject/Main.html Where ServletProject is your application context. 其中ServletProject是您的应用程序上下文。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Java Web应用程序-Servlet问题 - Java Web Application - Servlet Problem 当我们使用Build Path选项在Dynamic Web Project中创建servlet时,eclipseIDE中Servlet.jar有什么需求? - what is the need of Servlet.jar in eclipseIDE when we create a servlet in Dynamic Web Project using Build Path option? Java-在Eclipse动态Web项目中将javascript连接到servlet - Java - Connecting javascript to servlet in eclipse dynamic web project 使用 Smack 构建 Java Web 项目时出现异常 - Get an Exception when i using the Smack to build a java web project Java Web servlet无法正常工作 - Java web servlet not working 使用Java Web应用程序上载文件,但不使用Java Servlet - Upload file with java web application but not using Java servlet 使用过滤器时的Java Servlet映射 - Java Servlet mapping when using a filter 使用Java而不使用Servlet和Tomcat创建简单的网页 - Creating a simple web page using Java without using Servlet and Tomcat 在Web应用程序/ Servlet中启动时,休眠的java.lang.ExceptionInInitializerError - Hibernate java.lang.ExceptionInInitializerError when launched in web application/servlet 面对 osweb.servlet.PageNotFound:我的 spring 引导项目中的 GET / 问题没有映射 - Facing o.s.web.servlet.PageNotFound : No mapping for GET / problem in my spring boot project
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM