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

500错误

<%@ 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=UTF-8">

<title>Insert title here</title>

</head>

<body>

<body>

<h1>

第一个Servlet小例子

</h1>

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

</body>

</html>





package servlet;


import java.io.IOException;

import java.io.PrintWriter;


import javax.servlet.ServletException;

import javax.servlet.http.HttpServlet;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;


public class HelloServlet extends HttpServlet {


@Override

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

// TODO Auto-generated method stub

System.out.println("处理get()方法。。。");

PrintWriter out =response.getWriter();

out.println("<strong>Hello Servlet!</strong><br>");

}


@Override

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

// TODO Auto-generated method stub

System.out.println("处理post()方法。。。");

PrintWriter out =response.getWriter();

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

out.println("<strong>Hello Servlet!</strong><br>"); }


}





<?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" 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>MyFirstServlet</display-name>

  <welcome-file-list>

    <welcome-file>index.html</welcome-file>

    <welcome-file>index.htm</welcome-file>

    <welcome-file>index.jsp</welcome-file>

    <welcome-file>default.html</welcome-file>

    <welcome-file>default.htm</welcome-file>

    <welcome-file>default.jsp</welcome-file>

  </welcome-file-list>

  

  

  <servlet>

  <servlet-name>HelloServlet</servlet-name>

  <servlet-class>servlet.HelloServtet</servlet-class>

  </servlet>

  <servlet-mapping>

  <servlet-name>HelloServlet</servlet-name>

  <url-pattern>/servlet/HelloServlet</url-pattern>

  </servlet-mapping>

</web-app>

http://img1.sycdn.imooc.com//5781e0530001e21a09040620.jpg



求解决


正在回答

2 回答

<servlet-class>servlet.HelloServtet</servlet-class>

web.xml 配置文件里类名写错了。

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

qq_是狼何必装羊__0 提问者

非常感谢!
2016-07-14 回复 有任何疑惑可以回复我~

<servlet>

  <servlet-name>HelloServlet</servlet-name>

  <servlet-class>servlet.HelloServtet</servlet-class>   这里错了看清楚类名

  </servlet>

  <servlet-mapping>

  <servlet-name>HelloServlet</servlet-name>

  <url-pattern>/servlet/HelloServlet</url-pattern>  这里错了

  </servlet-mapping>


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

qq_是狼何必装羊__0 提问者

我的代码没错,用别人的电脑验证是没错的,我卸载了myeclipse,然后重装就正确了
2016-07-14 回复 有任何疑惑可以回复我~
#2

qq_是狼何必装羊__0 提问者 回复 qq_是狼何必装羊__0 提问者

发错地方了。。。。。
2016-07-14 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信