回 帖 发 新 帖 刷新版面

主题:谁会servlet啊

我用eclipse新建一个动态网站工程,主类名是HelloWorld,但在类名上老报错:
The serializable class HelloWorld does not declare a static final
serialVersionUID field of type long
运行时tomcat报错:type Status report

message /test/HelloWorld

description The requested resource (/test/HelloWorld) is not available.


--------------------------------------------------------------------------------

怎么回事啊,谁能告诉我啊,谢谢!!!1[em10]

源码是:
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
* Servlet implementation class for Servlet: HelloWorld
*
*/
public class HelloWorld extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet {
    /* (non-Java-doc)
     * @see javax.servlet.http.HttpServlet#HttpServlet()
     */
    public HelloWorld() {
        super();
    }       
    
    /* (non-Java-doc)
     * @see javax.servlet.http.HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
    }      
    
    /* (non-Java-doc)
     * @see javax.servlet.http.HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
    }                 
}

回复列表 (共5个回复)

沙发

呵呵,我经过编译后运行,
没有报错.但也没有什么内容显示.

板凳

你在web.xml中定义没定义这个servlet啊。

3 楼

用Eclipse 3.1+myEclipse开发Servlet,会出现以下错误信息:

“the serializable class 'myClassName' does not declare a static final serialVersionUID field of the tupe long ".

非常让人讨厌,可以点:

Eclipse --- window --- prefrences --- java ---- compile ----style

最后一项:serializable class without serialVersionUID

改成 ignore就可以啦。

4 楼

楼上的,看下楼主的错误。是找不到路径!所以很有可能是没有定义这个Servlet或者定义的路径有错。

serverlet mapping中的路径是相对于上下文的,不是相对于根的。

比如:有个web工程是testweb,一个Servlet的路径写成/testweb/testServlet。那访问的地址是localhost:8080/testweb/testweb/testServlet

5 楼

谢谢各位了

我来回复

您尚未登录,请登录后再回复。点此登录或注册