简体   繁体   English

在Eclipse中运行Web项目时出错

[英]Error running web project in eclipse

I am a newbie to servlets. 我是servlet的新手。 I created a dynamic web project in eclipse. 我在eclipse中创建了一个动态Web项目。 I have following files in my project 我的项目中有以下文件

home.html validateServlet.java home.html validateServlet.java

I have defined validated servlet as an action in home.html form. 我已经将经过验证的servlet定义为home.html形式的操作。 However when I run it, I get http status 404. Below is the hierarchy of my project 但是,当我运行它时,我得到的HTTP状态为404。

Project
Java Resources
   src
     com.servlets
    ValidateServlet.java
build
WebContent
    META-INF
    WEB-INF
        web.xml
    hello.html

Contents of my web.xml are as follows: 我的web.xml的内容如下:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"    xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web- app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>Website</display-name>
<servlet>
<description></description>
<display-name>ValidateServlet</display-name>
<servlet-name>validate</servlet-name>
<servlet-class>com.oracle.coen235.servlets.ValidateServlet</servlet-class>
</servlet>
</web-app>

In my hello.html, action is specified as , 在我的hello.html中,动作指定为,

What might be the issue? 可能是什么问题? I guess I am not able to generate the class file for my servlet. 我想我无法为我的servlet生成类文件。 Can anyone guide me through this problem? 谁能指导我解决这个问题?

You seem to mix things up. 你似乎把事情弄混了。

<servlet-class>com.oracle.coen235.servlets.Validate</servlet-class>

Should list the full class name. 应该列出完整的类名。 I don't see your package name. 我看不到您的包裹名称。

It should be 它应该是

<servlet-class>com.oracle.coen235.servlets.ValidateServlet</servlet-class>

or whatever your package name is. 或任何包裹名称。

We are you mapping your servlet to a path? 我们正在将servlet映射到路径吗? It should be something like: 应该是这样的:

 <servlet-mapping>
      <servlet-name>validate</servlet-name>
      <url-pattern>/validate</url-pattern>
 </servlet-mapping>

or an annotation directly in your servlet class. 或直接在servlet类中的注释。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM