java_web/java/com/demo/ConfigDemoServlet.java
2024-11-25 19:06:50 +08:00

44 lines
1.3 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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>");
}
}