springMVC 多 dispatcherServlet 配置

来源:互联网 发布:网络流行语大全网站 编辑:程序博客网 时间:2024/06/05 08:11

                  springMVC 注解流行使用,也就面临一个问题,如果我们的Xml配置文件只有一个,那么在多人共同开发时,大家都不知道其他人注解的名称,

就会注解重复,或者我们需要根据业务不同,我们需要进行不同处理,这是  就需要配置多个 dispatcherServlet ,对不同的URL进行分发。

                配置 如下

                  web.xml

<!--************* spring 主xml 文件配置 *************--><context-param><param-name>contextConfigLocation</param-name><param-value>/WEB-INF/classes/applicationContext.xml</param-value></context-param><!--**************  ************** --><servlet><servlet-name>common</servlet-name><servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class><load-on-startup>1</load-on-startup></servlet><servlet><servlet-name>rest</servlet-name><servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class><load-on-startup>1</load-on-startup></servlet><servlet><servlet-name>validate</servlet-name><servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class><load-on-startup>1</load-on-startup></servlet><servlet-mapping><servlet-name>common</servlet-name><url-pattern>*.do</url-pattern></servlet-mapping><servlet-mapping><servlet-name>rest</servlet-name><url-pattern>/rest/*</url-pattern></servlet-mapping><servlet-mapping><servlet-name>validate</servlet-name><url-pattern>/jm/validate/*</url-pattern>

    我们先配置 主xml  ,spring  公用的Bean ,包括数据库连接/数据源配置 ,事务配置 等,然后是分xml,我们 可以根据开发人员配置,或根据 业务配置,

所有的分xml  均可以访问主xml  上的bean

     spring 默认xml 文件命名为     xxx-serlvet.xml,存放在  web-inf  下,所以 我们需要创建 分 xml 文件  common-servlet.xml,rest-servlet.xml,validate-servlet.xml

jsp页面 如图

 

<%@ page language="java" import="java.util.*" pageEncoding="GBK"%><%String path = request.getContextPath();String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html>  <head>    <base href="<%=basePath%>">        <title>My JSP 'index.jsp' starting page</title><meta http-equiv="pragma" content="no-cache"><meta http-equiv="cache-control" content="no-cache"><meta http-equiv="expires" content="0">    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"><meta http-equiv="description" content="This is my page"><!--<link rel="stylesheet" type="text/css" href="styles.css">-->  </head>  <script type="text/javascript">  function show(){  var aac001=document.getElementById("aac001").value;   var url= "<%=path%>/person/showPerson.do?aac001="+aac001;  var form = document.f1;    form.action =url;  alert(url);  form.submit();  }  function xs(){  var aac001=document.getElementById("aac001").value;   var url= "<%=path%>/jm/validate/login/"+aac001;  var form = document.f1;  form.method="get";  form.action =url;  alert(url);  form.submit();  }  </script>  <body>   <form method="post" id="f1" name="f1"  action="person/showPerson.do">   <input type="text" id="aac001">   <input type="button"  value="hibernate测试"  onclick="show()">   <input type="button"  value="hibernate测试2222"  onclick="xs()">   </form>   <a href="<%=path%>/rest/showPower">权限显示</a>   <a href="<%=path%>/rest/login">测试111</a>   <a href="<%=path%>/jm/validate/xs">测试23232</a>  </body></html>


 

 


 

0 0
原创粉丝点击