如何在Eclipsed中编写第一个servlet类

时间:2013-08-20 07:11:51

标签: java jsp servlets

package com.example;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class Helloworld
 */
@WebServlet("/Helloworld")

public class Helloworld extends HttpServlet {
    private static final long serialVersionUID = 1L;

    /**
     * @see HttpServlet#HttpServlet()
     */
    public Helloworld() {
        super();
        // TODO Auto-generated constructor stub
    }

    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
    }

    /**
     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
    }

}

我创建了一个类hello-world并添加了Servelte API,但是我收到错误@WebServlet("/Helloworld")并显示错误消息 [注释类型WebServlet的属性值未定义] 。< / p>

请告诉我如何修复它?

1 个答案:

答案 0 :(得分:0)

http://docs.oracle.com/javaee/6/api/javax/servlet/annotation/WebServlet.html

尝试添加属性值:@WebServlet(value =“/ Helloworld”)