eclipse jee+tomcat8.0.x+servlet3.1 采用注释的方法,在jsp调用报错找不到

来源:1-4 使用MyEclipse编写Servlet

IOldCat

2016-05-18 23:01

<%@ page language="java" import="java.util.*" contentType="text/html; charset=utf-8"%>



<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

  <head>

    

    <title>My JSP 'index.jsp' starting page</title>

<meta http-equiv="pragma" content="no-cache">

<meta http-equiv="cache-control" content="no-cache">

<meta http-equiv="expires" content="0">    

<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">

<meta http-equiv="description" content="This is my page">

<!--

<link rel="stylesheet" type="text/css" href="styles.css">

-->

  </head>

  

  <body>

     <h1>使用Eclipse创建Servlet小例子</h1>

    <hr>

    <a href="/HelloServlet">Get方式请求HelloServlet</a><br>

  </body>

</html>

//

//

package servlet;


import java.io.IOException;

import javax.servlet.Servlet;

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 HelloServlet

 */

@WebServlet(asyncSupported = true, urlPatterns = { "/HelloServlet" })

public class HelloServlet extends HttpServlet implements Servlet {

private static final long serialVersionUID = 1L;

       

    /**

     * @see HttpServlet#HttpServlet()

     */

    public HelloServlet() {

        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

response.getWriter().append("Served at: ").append(request.getContextPath());

}


/**

* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)

*/

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

// TODO Auto-generated method stub

doGet(request, response);

}


}


写回答 关注

4回答

  • qq_画个圈圈诅咒你_03164602
    2016-12-21 21:19:03

    为什么这样还是访问不到地址

  • qq_浮華塵世荒年痛_03476721
    2016-06-30 16:38:39

    相比配置 web.xml ,我还是喜欢用注解。

  • IOldCat
    2016-05-19 21:24:33

    = =解决了 用了我一天

    盯叮町玎仃

    你好,请问是怎么解决的?

    2017-06-13 15:06:16

    共 1 条回复 >

  • IOldCat
    2016-05-18 23:02:43

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

    <html>

      <head>

        

        <title>My JSP 'index.jsp' starting page</title>

    <meta http-equiv="pragma" content="no-cache">

    <meta http-equiv="cache-control" content="no-cache">

    <meta http-equiv="expires" content="0">    

    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">

    <meta http-equiv="description" content="This is my page">

    <!--

    <link rel="stylesheet" type="text/css" href="styles.css">

    -->

      </head>

      

      <body>

         <h1>使用Eclipse创建Servlet小例子</h1>

        <hr>

        <a href="/HelloServlet">Get方式请求HelloServlet</a><br>

      </body>

    </html>

    //

    //

    package servlet;


    import java.io.IOException;

    import javax.servlet.Servlet;

    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 HelloServlet

     */

    @WebServlet(asyncSupported = true, urlPatterns = { "/HelloServlet" })

    public class HelloServlet extends HttpServlet implements Servlet {

    private static final long serialVersionUID = 1L;

           

        /**

         * @see HttpServlet#HttpServlet()

         */

        public HelloServlet() {

            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

    response.getWriter().append("Served at: ").append(request.getContextPath());

    }


    /**

    * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)

    */

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    // TODO Auto-generated method stub

    doGet(request, response);

    }


    }



JAVA遇见HTML——Servlet篇

本门课程在JSP课程的基础上,深入介绍Servlet的基础知识

160613 学习 · 1029 问题

查看课程

相似问题