web学习笔记

·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,strutsaction中定义类成员变量;若要定义则得注意线程安全问题。
     
不过webworkaction是线程安全的,对每一个请求都产生新的实例。

    ·基础层 不应该把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">


 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值