44 lines
1.3 KiB
Java
44 lines
1.3 KiB
Java
package com.demo;
|
||
|
||
import java.io.*;
|
||
import javax.servlet.*;
|
||
import javax.servlet.http.*;
|
||
import javax.servlet.annotation.*;
|
||
|
||
@WebServlet(
|
||
urlPatterns = { "/configDemo.do" },
|
||
initParams = {
|
||
@WebInitParam(name = "email", value = "hacker@163.com"),
|
||
@WebInitParam(name = "telephone", value = "8899123")
|
||
}
|
||
)
|
||
public class ConfigDemoServlet extends HttpServlet {
|
||
/**
|
||
*
|
||
*/
|
||
private static final long serialVersionUID = 1L;
|
||
String servletName = null;
|
||
ServletConfig config = null;
|
||
String email = null;
|
||
String telephone = null;
|
||
|
||
public void init(ServletConfig config) throws ServletException {
|
||
super.init(config);
|
||
this.config = config;
|
||
servletName = config.getServletName();
|
||
email = config.getInitParameter("email");
|
||
telephone = config.getInitParameter("telephone");
|
||
}
|
||
|
||
public void doGet(HttpServletRequest request, HttpServletResponse response)
|
||
throws ServletException, IOException {
|
||
|
||
response.setContentType("text/html;charset=gb2312");
|
||
PrintWriter out = response.getWriter();
|
||
out.println("<html><body>");
|
||
out.println("Servlet名称:" + servletName + "<br>");
|
||
out.println("Email地址:" + email + "<br>");
|
||
out.println("电话:" + telephone);
|
||
out.println("</body></html>");
|
||
}
|
||
} |