spring整合struts2(續)
//web.xml配置
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
<display-name>Spring_struts2</display-name>
<!-- Bootstraps the root web application context before servlet initialization -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:resources/spring/applicationContext.xml</param-value>
</context-param>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
<init-param>
<param-name>config</param-name>
<param-value>struts-default.xml,struts-plugin.xml,resources/struts2/struts.xml</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
</web-app>
注意:struts2配置檔案預設存放路徑在/WEB-INF/classes目錄下,即將struts.xml放在src的目錄下。
但是為了協作開發與方便管理,我們有時需要把struts.xml放到其他位置
struts2載入配置檔案都是先從自己的jar包和/WEB-INF/classes兩個預設的位置載入的。
若修改struts2配置檔案的存放位置,在web.xml配置過慮器,具體配置如下:
<init-param>
<param-name>config</param-name>
<param-value>struts-default.xml,
struts-plugin.xml,resources/struts2/struts.xml</param-value>
</init-param>
在這裡我把struts.xml放在了src下的resources/struts2包下,因為設定了<param-name>config</param-name>引數,所以struts-default.xml,struts-plugin.xml等原來struts2預設載入的檔案也需要手動指定,否則不會自動載入。
若不在這裡配置struts-default.xml,struts-plugin.xml,也可在struts.xml檔案中include將兩個檔案包含進來。
<include file="struts-default.xml" />
<include file="struts-plugin.xml" />
如若約定大於配置,多個子配置檔案的話可以採用掃描的方式如:
<include file="com/home/conf/struts-*.xml" />
或直接
<include file="com/home/conf/*.xml" />
//index.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<form action="test/loginAction.action" method="post">
使用者名稱:<input name="name" type="text" >
密碼:<input type="password" name="password">
<input type="submit" value="提交">
</form>
</body>
</html>
//success.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<s:property value="name"/>,歡迎回來.
</body>
</html>
//fail.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript" src="/js/jquery-1.4.2.js"></script>
</head>
<body>
<script type="text/javascript">
alert('登入失敗,請重試!');
window.location='../index.jsp';
</script>
</body>
</html>
執行結果:
相關文章
- spring整合struts2Spring
- Struts2【與Spring整合】Spring
- [求助] STRUTS2和SPRING整合問題Spring
- Mybatis整合Spring(ssm整合待續)-day04MyBatisSpringSSM
- 框架(Spring、Struts2和Hibernate三者)整合框架Spring
- 持續整合之 Spring Boot 實戰篇Spring Boot
- 整合持續整合工具
- struts2 + urlrewrite 整合注意事項
- iOS 持續整合iOS
- 持續整合持續部署持續交付_持續整合與持續部署之間的真正區別
- 持續整合、持續部署、持續交付、持續釋出
- 持續整合、持續交付、持續部署簡介
- Jenkins持續整合Jenkins
- Struts2,Hibernate,Spring 環境配置Spring
- Spring Boot整合Spring BatchSpring BootBAT
- Spring Boot整合Spring SecuritySpring Boot
- Spring Boot整合Spring AopSpring Boot
- Spring 整合 MyBatisSpringMyBatis
- mybatis整合springMyBatisSpring
- ActiveMq整合SpringMQSpring
- Spring整合MyBatisSpringMyBatis
- Spring整合JUnitSpring
- Spring整合WebSocketSpringWeb
- Spring Cloud 整合SpringCloud
- 持續整合配置之Nuget
- Taro 小程式持續整合
- 持續整合JenkinsBlueOcean初探Jenkins
- Jenkins持續整合配置Jenkins
- MyBatis(九) 整合Spring、整合SpringMVCMyBatisSpringMVC
- 淺談持續整合的理解以及實現持續整合,需要做什麼?
- 淺談持續整合(CI)、持續交付(CD)、持續部署(CD)
- 從持續整合到持續交付——DockerCloud概覽DockerCloud
- Spring Boot:整合Spring Data JPASpring Boot
- spring:spring與mybatis的整合SpringMyBatis
- spring-boot+spring-session整合SpringbootSession
- spring+redis的整合,使用spring-data-redis來整合SpringRedis
- Unit08: Spring與MyBatis整合 、 Spring整合MyBatis應用SpringMyBatis
- Flutter web 持續整合實踐FlutterWeb