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>
小草1434
慕侠7248830
相关分类