标签:prot 微软 nec fresh 编码 静态 简介 isp object
public class HelloServlet implements Servlet { @Override public void init(ServletConfig config) throws ServletException {} @Override public ServletConfig getServletConfig() {return null;} @Override public void service(ServletRequest req, ServletResponse res)throws ServletException, IOException {System.out.println("hello");} @Override public String getServletInfo() {return null;} @Override public void destroy() {} }
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"> <servlet> <servlet-name>HelloServlet</servlet-name> <servlet-class>com.atdongruan.web.servlet.HelloServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>HelloServlet</servlet-name> <url-pattern>/HelloServlet</url-pattern> </servlet-mapping> </web-app>/*
3.1 Servlet生命周期
3.1.1 Servlet初始化
<servlet> <servlet-name>HelloServlet</servlet-name> <servlet-class>省略</servlet-class> <init-param> <param-name>username</param-name> <param-value>root</param-value> </init-param> </servlet>
public abstract class GenericServlet implements Servlet, ServletConfig, java.io.Serializable{ private transient ServletConfig config; public GenericServlet() { } public void destroy() {} public String getInitParameter(String name) { return getServletConfig().getInitParameter(name); } public Enumeration getInitParameterNames() { return getServletConfig().getInitParameterNames(); } public ServletConfig getServletConfig() {return config; } public ServletContext getServletContext() { return getServletConfig().getServletContext(); } public String getServletInfo() { return ""; } public void init(ServletConfig config) throws ServletException { this.config = config; this.init(); } public void init() throws ServletException {} public void log(String msg) { getServletContext().log(getServletName() + ": "+ msg); } public void log(String message, Throwable t) { getServletContext().log(getServletName() + ": " + message, t); } public abstract void service(ServletRequest req, ServletResponse res) throws ServletException, IOException; public String getServletName() { return config.getServletName(); } }
|
问题1:Servlet的构造器调用了几次?
问题2:Servlet是线程安全的吗?
问题3:Servlet实例只能在第一次请求时被创建吗?
问题5:web.xml文件仅仅是看到的那么简单吗?
<servlet> <servlet-name>default</servlet-name> <servlet-class>org.apache.catalina.servlets.DefaultServlet</servlet-class> <init-param> <param-name>debug</param-name> <param-value>0</param-value> </init-param> <init-param> <param-name>listings</param-name> <param-value>false</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>default</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping>
<servlet> <servlet-name>jsp</servlet-name> <servlet-class>org.apache.jasper.servlet.JspServlet</servlet-class> <init-param> <param-name>fork</param-name> <param-value>false</param-value> </init-param> <init-param> <param-name>xpoweredBy</param-name> <param-value>false</param-value> </init-param> <load-on-startup>3</load-on-startup> </servlet> <servlet-mapping> <servlet-name>jsp</servlet-name> <url-pattern>*.jsp</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>jsp</servlet-name> <url-pattern>*.jspx</url-pattern> </servlet-mapping>
<session-config> <session-timeout>30</session-timeout> </session-config>
<mime-mapping> <extension>123</extension> <mime-type>application/vnd.lotus-1-2-3</mime-type> </mime-mapping>
8.1 ServletContext简介
8.2 获取ServletContext
8.3 域对象
8.4 获取当前应用的初始化参数
<context-param> <param-name>username</param-name> <param-value>root</param-value> </context-param> <context-param> <param-name>password</param-name> <param-value>1234</param-value> </context-param> </web-app>
8.5 获取项目根目录
8.6 获取资源的流和真实路径(物理路径)
9.4.1 转发
9.4.2 重定向
9.5 路径问题
9.5.1 服务器端路径
9.5.1 为什么要使用编码
9.5.3 请求编码
<Connector connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443" URIEncoding="utf-8" />
|
9.5.4 响应编码
9.5.5 URL编码
标签:prot 微软 nec fresh 编码 静态 简介 isp object
原文地址:http://www.cnblogs.com/WangKaitao/p/7352631.html