为了账号安全,请及时绑定邮箱和手机立即绑定

为什么使用eclipse总是出现404

index里面

<%@ page language="java" contentType="text/html; charset=utf-8"

    pageEncoding="utf-8"%>

<!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>Insert title here</title>

</head>

<body>

<a href="Helloservlet">你好</a>

<form action="/Helloservlet" method="post">

<input type="submit" value="很好"/>

</form>

</body>

</html>

Helloservlet里面的代码如下,没有配置web.xml因为已经有了注解

package servlet;


import java.io.IOException;

import java.io.PrintWriter;


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("/Helloservlet")

public class Helloservlet extends HttpServlet {

private static final long serialVersionUID = 1L;


    /**

     * Default constructor. 

     */

    public Helloservlet() {

        // 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

doPost(request, response);

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

System.out.println("很好");

PrintWriter out=response.getWriter();

response.setContentType("text/html;charset=utf-8");

out.println("<strong>xixi</strong>");

}


/**

* @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);

System.out.println("很好");

PrintWriter out=response.getWriter();

response.setContentType("text/html;charset=utf-8");

out.println("<strong>xixi</strong>");

}


}

但是一直出现以下问题,已经一个消失了都没有解决成功,求大神来解答

http://img1.sycdn.imooc.com//598ff065000146e906780303.jpg

正在回答

2 回答

我的是xml文件中<url-pattern>/Servlet/HelloServlet</url-pattern>的Servlet首字母是小写,改成大写就OK了

0 回复 有任何疑惑可以回复我~

路径出错,其实你应该直接访问页面,而不是访问servlet

0 回复 有任何疑惑可以回复我~
#1

Sang桑来迟

访问的是index.jsp页面,点击链接后的跳转页面
2018-08-06 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

为什么使用eclipse总是出现404

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信