package com.qf.xu;
import java.io.IOException;
import javax.servlet.Servlet;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
public class ServletDemo1 implements Servlet{
//当servlet销毁时的回调方法
@Override
public void destroy() {
// TODO Auto-generated method stub
}
//可以获取servlet的配置信息
@Override
public ServletConfig getServletConfig() {
// TODO Auto-generated method stub
return null;
}
//可以获取servlet的信息
@Override
public String getServletInfo() {
// TODO Auto-generated method stub
return "我是处理登录请求的";
}
//初始化servlet的方法
@Override
public void init(ServletConfig config) throws ServletException {
// TODO Auto-generated method stub
}
//servlet处理请求的方法。
@Override
public void service(ServletRequest req, ServletResponse res)
throws ServletException, IOException {
// TODO Auto-generated method stub
System.out.println("service执行了");
res.setCharacterEncoding("gb2312");
//res.getWriter().println("处理了请求");
res.getWriter().println("<html><head></head><body>");
for (int i = 0; i < 10; i++) {
res.getWriter().println("<input type='text' value='请输入用户名'/><br/>");
}
res.getWriter().println("</body></html>");
}
}
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0"
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_3_0.xsd">
<display-name></display-name>
<!-- 配置servlet和servlet-mapping -->
<servlet>
<servlet-name>Servlet1</servlet-name>
<servlet-class>com.qf.xu.ServletDemo1</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Servlet1</servlet-name>
<url-pattern>/Demo1</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
5 回复
添加回复
请先登陆