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

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>

一个人一时的旅行
浏览 1112回答 2
2回答

小草1434

粗略看了下代码,没有什么问题如果该工程是放在tomcat下运行的,【ROOT.war】的情况,浏览器直接访问ip:端口/ShopServlet?category=mmm即可,否则要将xxx.war 的项目名称还是面不了的ip:端口/xxx/ShopServlet?category=mmm

慕侠7248830

好歹说说啥错呀兄弟
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java