·request的几个常见API——
例如访问:http://localhost:4040/security/login?go=http://192.168.1.120:4040/iexchange/
request.getQueryString()=go=http://192.168.1.120:4040/iexchange/
request.getRequestURI()=/security/login
request.getRequestURL()=http://localhost:4040/security/login
request.getServletPath()=/login
·当多个客户端请求某一servlet时,其实是多个线程在使用同一实例。 所以servlet不是线程安全的。不要在servlet,jsp,struts的action中定义类成员变量;若要定义则得注意线程安全问题。
不过webwork的action是线程安全的,对每一个请求都产生新的实例。
·基础层 不应该把exception隐藏起来,应该继续throw异常或者抛出Runtime异常。在Spring框架,抛出Runtime异常是被广泛应用的。而在MVC的处理层则要对异常进行处理,要么重新包装(例如重新包装成ServletException),要么使用日志记录起来。
·如果Web应用使用Servlet 2.4以上的的规范,则无需在web.xml文件中配置标签库定义,因为Servlet 2.4规范会自动加载标签库定义文件。
·使用Spring来实现Servlet,只要实现org.springframework.web.servlet.mvc.Controller接口
public ModelAndView handleRequest(HttpServletRequest request,
HttpServletResponse response) throws Exception {
if( true ){
Map<String,String> model = new HashMap<String,String>();
model.put("errorMsg", "只有通过域名或者IP地址来访问才能单点登陆!");
return new ModelAndView("login",model);
}
return new ModelAndView("login");
}
同时需要在bean.xml中配置相关的bean配置:
<bean name="/login" class="bison.sample.LoginController" />
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
</bean>
使用EL表达式:要使用EL表达式,必须在web.xml中加入以下的文件头。
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">