2-5编程练习报错,请老师指点一下

HTTP Status 404 – Not Found


Type Status Report

Message /ServletProj/ShopServlet

Description The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.


Apache Tomcat/8.5.35

源代码

package com.imooc.book;

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 ServletProj extends HttpServlet{

    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String name=request.getParameter("category");
        String html="<h1 style='color:red'>hi,"+name+"!</h1><hr/>";
        System.out.println("返回给浏览器的响应数据为:"+html);
        PrintWriter out=response.getWriter();
        out.println(html);//将html发送回浏览器
        
    }
    

}

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
  <display-name>ServletProj</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>book</servlet-name>
    <servlet-class>com.imooc.book.ServletProj</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>book</servlet-name>
    <url-pattern>/ShopServlet</url-pattern>
  </servlet-mapping>
</web-app>

一个人一时的旅行
浏览 745回答 1
1回答

ewang1986

找不到对应的url映射方法,能提供详细的报错堆栈信息吗
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java