为什么我的超链接点进去老是500 或404

来源:1-3 手工编写第一个Servlet

weibo_柠檬橙子y_0

2016-10-29 21:46


//index.jsp

<%@ 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>第一个小程序</title>

</head>

<body>

<h1>第一个Servlet小例子</h1>

<hr>

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

</body>

</html>


//web.xml

<?xml version="1.0" encoding="UTF-8"?>

<web-app version="2.5" 

xmlns="http://java.sun.com/xml/ns/javaee" 

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 

xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 

http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

  <display-name></display-name>

  

  <welcome-file-list>

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

   </welcome-file-list>

   

  <servlet>

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

      <servlet-class>Servlet.HelloServlet</servlet-class>

  </servlet>

  

  <servlet-mapping>

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

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

  </servlet-mapping>

   

  </web-app>

  //HelloServlet 

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;


//继承于HttpServlet

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>");//用strong标签实现加粗br标签换行(html语言)

}


@Override

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

// TODO Auto-generated method stub

}


}


写回答 关注

1回答

  • kkskylin
    2016-10-30 18:33:17
    已采纳

    是不是这里错了?   <servlet-class>Servlet.HelloServlet</servlet-class>跟前面大写S 有关系不?我看你包名好像不是大写的吧?

    weibo_...

    是的 我太粗心了 谢谢你

    2016-10-31 09:11:09

    共 1 条回复 >

JAVA遇见HTML——Servlet篇

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

160615 学习 · 1029 问题

查看课程

相似问题