📄 paramservlet.java
字号:
import javax.servlet.*;import javax.servlet.http.*;import java.io.*;import java.util.*;public class ParamServlet extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // Set the content type header and start the HTMP document response.setContentType("text/html"); PrintWriter out = response.getWriter(); out.println("<html>"); out.println("<head><title>ParamServlet</title></head>"); out.println("<body>"); // fetch the ServletConfig that was stored by init() ServletConfig config = getServletConfig(); out.println("<br>This servlet's name is "+config.getServletName()); out.println("<br>It's init parameters are :<ul>"); Enumeration params = config.getInitParameterNames(); while (params.hasMoreElements()) { String name = (String)params.nextElement(); String value = config.getInitParameter(name); out.println("<li>"+name+" = "+value+"</li>"); } out.println("</ul>"); // Now let's look at the ServletContext ServletContext context = config.getServletContext(); out.println("<br>The server is "+context.getServerInfo()); out.println("<br>This server supports servlet version "+ context.getMajorVersion()+"."+ context.getMinorVersion()); // Try to read an attribute set in the server (will be null the first time) Object obj = context.getAttribute("com.wrox.ParamServletAttribute"); out.println("<br>The attribute is "+obj); // Now set an attribute that can be seen by all servlets in this // context (including this one next time) context.setAttribute("com.wrox.ParamServletAttribute", "AttributeValue"); out.println("</body></html>"); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -