Struts2.1.6 framework for integration with the Spring2.5.6

2008-07-16  来源:本站原创  分类:Java  人气:214 

1, in the MyEclipse in the New Project (test)
2, Struts package into a temporary import the necessary packages, other packages will be used when the import:
commons-fileupload-1.2.1.jar
commons-logging-1.0.4.jar
freemarker-2.3.13.jar
ognl-2.6.11.jar
struts2-core-2.1.6.jar
xwork-2.1.2.jar
3, copy the example directory in the Struts program WEB-INF \ classes \ struts.xml file and paste it into the project's src directory, the main retain their file header:

1 <? Xml version = "1.0" encoding = "GBK"?>
2 <! DOCTYPE struts PUBLIC
3 "- / / Apache Software Foundation / / DTD Struts Configuration 2.0 / / EN"
4 "http://struts.apache.org/dtds/struts-2.0.dtd">
5
6 <struts>
7 <package name = "struts2" extends = "struts-default">
8
9 </ package>
10 </ struts>

4, configure web.xml

1 <? Xml version = "1.0" encoding = "UTF-8"?>
2 <web-app version = "2.5" xmlns = "http://java.sun.com/xml/ns/javaee"
3 xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance"
4 xsi: schemaLocation = "http://java.sun.com/xml/ns/javaee
5 http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd ">
6
7 <filter>
8 <filter-name> struts2 </ filter-name>
9 <filter-class>
10 org.apache.struts2.dispatcher.FilterDispatcher
11 </ filter-class>
12 </ filter>
13 <filter-mapping>
14 <filter-name> struts2 </ filter-name>
15 <url-pattern> / * </ url-pattern>
16 </ filter-mapping>
17
18 <welcome-file-list>
19 <welcome-file> index.jsp </ welcome-file>
20 </ welcome-file-list>
21 </ web-app>

5, the introduction of Spring package, in the dist directory
spring.jar
6, in the src directory to set up three documents
applicationContext-actions.xml
applicationContext-beans.xml
applicationContext-common.xml
These three instruments are in fact applicationContext.xml decomposition, in order to avoid all of the configuration on the same file, and cause confusion.
Their structures were characterized as follows:

1 <? Xml version = "1.0" encoding = "GBK"?>
2
3 <beans xmlns = "http://www.springframework.org/schema/beans"
4 xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance"
5 xmlns: context = "http://www.springframework.org/schema/context"
6 xmlns: tx = "http://www.springframework.org/schema/tx"
7 xmlns: aop = "http://www.springframework.org/schema/aop"
8 xsi: schemaLocation = "http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
9 http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
10 http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
11 http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd ">
12
13 </ beans>

7, need to be configured in the web.xml

<Context-param>
<Param-name> contextConfigLocation </ param-name>
<Param-value> classpath *: applicationContext-*. xml </ param-value>
</ Context-param>

<Listener>
<Listener-class>
org.springframework.web.context.ContextLoaderListener
</ Listener-class>
</ Listener>

Pre-configuration of a piece of code because we have configured the following piece of code, after which the default configuration is to find applicationContext.xml under WEB-INF file, we are now change into the src directory and make the file decomposition.

8, need to introduce another package in Struts2
struts2-spring-plugin-2.1.6.jar
9, test whether the integration of the success of (1) the establishment of the page login.jsp, welcome.jsp, error.jsp, respectively for the login page, login success page, error page
login.jsp

1 <% @ page language = "java" contentType = "text / html; charset = GB18030"
2 pageEncoding = "GB18030"%>
3 <% @ taglib prefix = "s" uri = "/ struts-tags"%>
4 <! DOCTYPE html PUBLIC "- / / W3C / / DTD HTML 4.01 Transitional / / EN" "http://www.w3.org/TR/html4/loose.dtd">
5 <html>
6 <head>
7 <meta http-equiv = "Content-Type" content = "text / html; charset = GB18030">
8 <title> login page </ title>
9 </ head>
10 <body>
11 <s: form action = "login" method = "post">
12 <s: textfield name = "username" label = "username" />
13 <s: password name = "password" label = "password" />
14 <s: submit value = "submit" />
15 </ s: form>
16 </ body>
17 </ html>

welcome.jsp

1 <% @ page language = "java" contentType = "text / html; charset = GB18030"
2 pageEncoding = "GB18030"%>
3 <! DOCTYPE html PUBLIC "- / / W3C / / DTD HTML 4.01 Transitional / / EN" "http://www.w3.org/TR/html4/loose.dtd">
4 <html>
5 <head>
6 <meta http-equiv = "Content-Type" content = "text / html; charset = GB18030">
7 <title> Login successful </ title>
8 </ head>
9 <body>
10 User Name: $ (username)
11 <br>
12 password: $ (password)
13 <br>
14 </ body>
15 </ html>

(2) to build packages com.test.manager and storage of business logic processing, respectively com.test.manager.impl interface and its implementation, namely the establishment of interfaces LoginManager.java and its implementation LoginManagerImpl.java
LoginManager.java

1 package com.test.manager;
2
3 public interface LoginManager (
4 public boolean isLogin (String username, String password);
5)

LoginManagerImpl.java, only a test to determine whether the user name password intrl, intrl, if you log on successfully

1 package com.test.manager.impl;
2
3 import com.test.manager.LoginManager;
4
5 public class LoginManagerImpl implements LoginManager (
6 public boolean isLogin (String username, String password)
7 (
8 if (null! = Username & & null! = Password & & "intrl". Equals (username.trim ()) & & "intrl". Equals (password.trim ()))
9 (
10 return true;
11)
12 return false;
13)
14)

(3) applicationContext-beans.xml the implementation class configuration to allow Spring to manage

<Bean id = "loginManager"
class = "com.test.manager.impl.LoginManagerImpl">
</ Bean>

(4) to create package com.test.action used to store action, and create LoginAction.java, inheritance ActionSupport received from the page class contains parameters username, password, and business logic processing class LoginManager type loginManager, give username and password settings get , set, set set to loginManager ways to let Spring inject our automatic; overwrite the parent class

1 package com.test.action;
2
3 import com.opensymphony.xwork2.ActionSupport;
4 import com.test.manager.LoginManager;
5
6 @ SuppressWarnings ( "serial")
7 public class LoginAction extends ActionSupport (
8 private LoginManager loginManager;
9 private String username;
10 private String password;
11
12 public String getUsername () (
13 return username;
14)
15
16 public void setUsername (String username) (
17 this. Username = username;
18)
19
20 public String getPassword () (
21 return password;
22)
23
24 public void setPassword (String password) (
25 this. Password = password;
26)
27
28 public void setLoginManager (LoginManager loginManager) (
29 this. LoginManager = loginManager;
30)
31
32 @ Override
33 public String execute () throws Exception (
34
35 if (loginManager.isLogin (username, password))
36 (
37 return SUCCESS;
38)
39 return INPUT;
40)
41)

(5) be configured in the applicationContext-actions.xml also allow Spring to manage LoginAction

<Bean id = "loginAction" class = "com.test.action.LoginAction"
scope = "prototype">
<Property name = "loginManager" ref = "loginManager"> </ property>
</ Bean>

(6) struts.xml the configuration to handle the request submitted by the page, configure the action: login, login and must hold login.jsp in the form of the action attribute name matching. At this point struts.xml documents are as follows:

1 <? Xml version = "1.0" encoding = "GBK"?>
2 <! DOCTYPE struts PUBLIC
3 "- / / Apache Software Foundation / / DTD Struts Configuration 2.0 / / EN"
4

Spring2 jar package Analysis | blackbirdjs

  • 10:57
  • View (37)
  • Comments (0)
  • Category: Struts2
  • Related Recommendation
Comments
Comments
相关文章
  • Struts2.1.6 framework for integration with the Spring2.5.6 2008-07-16

    1, in the MyEclipse in the New Project (test) 2, Struts package into a temporary import the necessary packages, other packages will be used when the import: commons-fileupload-1.2.1.jar commons-logging-1.0.4.jar freemarker-2.3.13.jar ognl-2.6.11.jar

  • XFire Web Service framework for integration with Tomcat (1) 2010-12-30

    XFire Web Service framework for integration with Tomcat Liu Yan Although XFire is outdated, but the frustration with the previous projects the company is jdk1.4, so I can only choose the old chariot XFire Web Service development. First, we create a w

  • Using Struts2 spring hibernate framework development project --------- verify that the user name is available 2011-05-18

    Using Struts2 spring hibernate framework development project --------- verify that the user name is available Framework with three major development projects, when we registered users, it often requires the database user name is unique, so we need th

  • Spring2.5.Struts2.Ibatis development framework structures (c) 2011-05-24

    Third, the integration of Spring2.5, Struts2, iBATIS, DBCP, Log4j 3.1 what's the point? Why should "integrate" the framework? In the program code by the programmer responsible for the processing and control everything is not it? With so many fra

  • s2sh framework for integration of 2010-03-29

    struts2, spring and hibernate integration of the development. The integration of the three main spring of this is to use the middle frame, up to integrate struts2, downward integration of hibernate. The specific configuration is as follows. struts-co

  • Framework for integration: is the server at startup time, load the appropriate framework for the configuration file 2010-03-18

    The integration of the framework : That is when the server was started, load the appropriate frame profile

  • Struts2 + jquery.validate framework to achieve the user name exists 2010-04-18

    In the project registration page need to determine whether there is user name, using the jquery validation framework for remote method to implement. 1, js script: jQuery.validator.addMethod ("usename", function (value, element) ( return this.opt

  • Spring2.5.Struts2.Ibatis development framework to build (a) 2011-05-24

    First, download the framework 1.1 Struts2 Framework Struts2 framework developed in WebWork, now donated to the Apache open-source organization, the latest version of Apache Struts2 framework of the official site from the Struts2 in the project to obt

  • Spring2.5.Struts2.Ibatis development framework structures (b) 2011-05-24

    datebase.error = \ u6570 \ u636e \ u5e93 \ u64cd \ u4f5c \ u9519 \ u8bef \ uff01 \ uff01 \ uff01 validCode_error = \ u9a8c \ u8bc1 \ u7801 \ u9519 \ u8bef \ uff01 \ uff01 retistSdk.error = \ u6ce8 \ u518cSDK \ u5931 \ u8d25 \ uff01 \ u8bf7 \ u68c0 \

  • xser php framework successful integration of the powerful routing components Qee 2010-05-28

    See: http://qeephp.com/bbs/thread-11007-1-1.html Picture so:

  • XFire Web Service framework for integration with Tomcat (2) 2010-12-30

    Wsdl as follows <? Xml version = "1.0" encoding = "UTF-8"?> <Wsdl: definitions targetNamespace = "http://webservice" xmlns: soapenc12 = "http://www.w3.org/2003/05/soap-encoding" xmlns: tns = "http://we

  • SSH Integration Series 1 - Configuration Struts2.1.8.1, and test the first action 2008-10-29

    This article, first as a series of articles, will begin by explaining the following points: 1. System Platform: Struts: 2.1.8.1 Spring: Hibernate: tomcat: 5.5.27 MyEclipse: 7.5 2. This series of articles as the original article, if it appears in the

  • SSH framework of the integration step 2010-11-08

    SSH framework of integration steps: 1. Built web project 2. Import struts2.0 the jar package (plus the five basic struts2-spring-plugin-2.0.14.jar) 3. Into the jar package spring, hibernate here, plus the associated package can be completed with myec

  • Struts2 framework security flaws 2009-12-09

    Abstract This article describes the development of popular java framework for struts2, and webwork some of the security flaws, and illustrates the framework itself as well as developers use the framework, arising from security problems, and the autho

  • #翻译NO.1# --- Spring Integration Framework 2012-12-12

    Part II. Overview of Spring Integration Framework Spring Integration provides an extension of the Spring programming model to support the well-known Enterprise Integration Patterns. It enables lightweight messaging within Spring-based applications an

  • Xiang Jie struts2 in struts.properties 2010-03-29

    Struts 2 framework has two key configuration files: struts.xml and struts.properties One struts.xml document management applications is mainly responsible for the Action mapping, as well as the definition of Action contained in the Result. In additio

  • Struts2 properties file Xiangjie 2010-03-29

    struts.configuration This attribute specifies the Struts 2 configuration file loads the configuration file manager. The property's default value is org.apache.Struts2.config.DefaultConfiguration, which is Struts 2 default configuration file manager.

  • Struts2 Study Notes 2 ----- Struts2 in constant (ie, default.properties file) Xiangjie 2010-03-29

    The struts2-core-2.1.8.1.jar/ora.apache.struts2/default.properties can see a lot of Struts2's constant, when you change some constants in the development contribute to the development. Sometimes programs also need to change inside the constant: So to

  • struts1, WebWork as well as profiles and compare struts2 2010-03-29

    Struts 1 Introduction and problems in perspective from the past years, Struts 1 is a MVC framework for all indisputable winner, regardless of market share, is still owned by the development of people, Struts 1 have incomparable to other MVC framework

  • struts2 build environment 2010-04-23

    Struts2 environmental requirements Apache Struts2 environmental requirements are as follows: Servlet API 2.4 JSP API 2.0 Java 5 Need to be reminded that, in the Struts will be used in the Annotation, so please upgrade to JDK version 1.5. Environment