httprequest请求时序和spingMVC

来源:互联网 发布:mac系统常用软件下载 编辑:程序博客网 时间:2024/06/07 16:32

1. http://blog.sina.com.cn/s/blog_667ab8240101gfd6.html

职责链模式


对与多个匹配的Filter,哪个先执行呢? 

JSR中说明的是,按照多个匹配的Filter,是按照其在web.xml中配置的顺序来执行的。


2. spingMVC 

jsp--->filter--servlet(control)--->db


3. js到servlet

JSP传值给Servlet有几种形式:Form表单传值,url传值,其他方式传值

a、form表单传值:

JSP页面有:<input type="radio" name="staffdepartment" value="1" id="department1" />,将department的id传到Sevlet

中,在程序中如下:ServletRequest request;String staffdepartment=request.getParameter("staffdepartment");可获取jsp传的department,但要获取id还要进行转化:int int_staffdepartment=Integer.parseInt(staffdepartment);

b、url传值

比如这里的 <a>标签的 href属性与 <form>标签的 action属性的值 "JspServlet?action=toServlet",在 servlet同样用 request.getParameter("action")获取;

c、Java代码传值

java片段代码,servlet只能接到 session.setAttribute("testSession","Hello session")的内容,而接不到 request的内容。在 servlet里用 request.getSession().getAttribute("testSession")获取 session内容。


servlet返回js

具体实现如下:

java代码:String   a= "abccdefg "; 
             request.setAttribute( "ValueA ",a); 
             request.getRequestDispatcher( "网址/jsp页面 ").forward(request,response); 

jsp页面:

<%

String   s   =(String)request.getAttribute( "ValueA ");

%>

jsp页面就可以取出Servlet的值。

另外springMVC中还可以用

mv.setViewName("system/admin/login"); 返回jsp



ApplicationContext.xml/   

<property name="unauthorizedUrl" value="/login_toLogin" />


---------------------------------------------------------------------------------------------------------------

ApplicationContext.xml中shiroFilter和web.xml中的关系

答:而 要在Spring中使用Shiro的话,可在web.xml中配置一个DelegatingFilterProxy,DelegatingFilterProxy作用是自动到Spring容器查找名字为shiroFilter(filter-name)的bean并把所有Filter的操作委托给它。

0 0
原创粉丝点击