SSH Integration Series 1 - Configuration Struts2.1.8.1, and test the first action

2008-10-29  来源:本站原创  分类:Java  人气:308 

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 text quoted, it will certainly give labeling.
3. Writing Objective:
a. re-familiar with the SSH configuration, and want to SSH in transmission of the latest framework for integration;
b. This will be a detailed record of each process, all processes are hands-on, as a future reference, and good faith to receive all the guidance and recommendations There is also the way to the development of people just entering such an entry template.
4. In the last article, will release the source code.

Ⅰ . Configuration Struts2.1.8.1:
1. Download the latest Struts2.1.8.1
2. Wdpweb build web project
3. Introduction to bag
4. FilterDispatcher in the web.xml to configure filters
5. Configuration struts.xml

1. Download the latest Struts2.1.8.1
Struts as an Apache project, of course, is to download Apache's official website. A book mentioned here is the official website recommended "Stating Struts2", and to download a Chinese version of "simple terms Struts2", in the face of the Documentation section Struts2 home page to download (requires registration before downloading), for study and use Struts2 very Help .

2. Wdpweb build web project

3. The introduction to package <br /> will Struts2.1.8.1 the lib folder of the six jar package:
commons-fileupload-1.2.1.jar
commons-logging-1.0.4.jar
freemarker-2.3.15.jar
ongl-2.7.3.jar
struts2-core-2.1.8.1.jar
xwork-2.1.6.jar
Copied to the web project in the / WEB-INF/lib directory.

Note: In the past, usually just after the 5 jar package, but in 2.1.8.1 version, if there is no commons-fileupload-1.2.1.jar, tomcat startup will report the following error:

2010-3-10 16:28:31 com.opensymphony.xwork2.util.logging.commons.CommonsLogger error
 Serious  : Dispatcher initialization failed
Unable to load configuration. - bean - jar:file:/D:/apache-tomcat-5.5.27/apache-tomcat-5.5.27/webapps/wdpweb/WEB-INF/lib/struts2-core-2.1.8.1.jar!/struts-default.xml:47:178
        --
Caused by: Unable to load bean: type:org.apache.struts2.dispatcher.multipart.MultiPartRequest class:org.apache.struts2.dispatcher.multipart.JakartaMultiPartRequest - bean - jar:file:/D:/apache-tomcat-5.5.27/apache-tomcat-5.5.27/webapps/wdpweb/WEB-INF/lib/struts2-core-2.1.8.1.jar!/struts-default.xml:47:178
        --
Caused by: java.lang.NoClassDefFoundError: org/apache/commons/fileupload/RequestContext
        --
Caused by: java.lang.ClassNotFoundException: org.apache.commons.fileupload.RequestContext
        --
2010-3-10 16:28:31 org.apache.catalina.core.StandardContext filterStart
 Serious  : Exception starting filter Struts2
Unable to load configuration. - bean - jar:file:/D:/apache-tomcat-5.5.27/apache-tomcat-5.5.27/webapps/wdpweb/WEB-INF/lib/struts2-core-2.1.8.1.jar!/struts-default.xml:47:178
        --
Caused by: Unable to load configuration. - bean - jar:file:/D:/apache-tomcat-5.5.27/apache-tomcat-5.5.27/webapps/wdpweb/WEB-INF/lib/struts2-core-2.1.8.1.jar!/struts-default.xml:47:178
        --
Caused by: Unable to load bean: type:org.apache.struts2.dispatcher.multipart.MultiPartRequest class:org.apache.struts2.dispatcher.multipart.JakartaMultiPartRequest - bean - jar:file:/D:/apache-tomcat-5.5.27/apache-tomcat-5.5.27/webapps/wdpweb/WEB-INF/lib/struts2-core-2.1.8.1.jar!/struts-default.xml:47:178
        --
Caused by: java.lang.NoClassDefFoundError: org/apache/commons/fileupload/RequestContext
        --
Caused by: java.lang.ClassNotFoundException: org.apache.commons.fileupload.RequestContext
        --
2010-3-10 16:28:31 org.apache.catalina.core.StandardContext start
 Serious  : Error filterStart
2010-3-10 16:28:31 org.apache.catalina.core.StandardContext start
 Serious  : Context [/wdpweb] startup failed due to previous errors

4. FilterDispatcher in the web.xml to configure filters
FilterDispatcher is a servlet filter, which is the entire Web application Struts2 configuration items need to "web.xml" in the configuration.
Code is as follows:

<filter>
                <!-- filter-name You can customize, but to guarantee and following  filter-mapping Filter-name consistent in   -->
                <!--  This will ensure that the filter and  filter-mapping One-to-one   -->
                <filter-name>Struts2</filter-name>
                <!--  This core interceptor FilterDispatcher can  struts2-core Easily found in the package   -->
                <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
        </filter>

        <filter-mapping>
                <filter-name>Struts2</filter-name>
                <url-pattern>/*</url-pattern>
        </filter-mapping>
        <!-- FilterDispatcher -->

5. Configuration struts.xml
Struts2 source package from the examples of projects in a struts.xml copy to the src directory, the principal is to copy DTD.

<!-- DTD: A document type definition  (Document Type Definition) -->
<!-- XML Document type definition-offers  XML Each element in the file by using the structure information   -->
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">

In <structs> </ structs> tag to write this great package label:

<!-- name:package The only signs, custom  :
        extends: Specify the package inherits package  , Generic inheritance  struts-default.xml:
        namespace: Namespaces provide a URL to the  Package Mapping
        -->
        <package name="Struts2" extends="struts-default" namespace="/">
                <!-- action -->
        </package>

Which, namespace specified in the program after the release of the maps in the url path, such as:
namespace ="/", browser path: http://localhost:8080/wdpweb/ ***. action
namespace = "/ pak1", the browser path: http://localhost:8080/wdpweb/pak1/ ***. action
namespace = "/ pak2", the browser path: http://localhost:8080/wdpweb/pak2/ ***. action

Ⅱ . The first action
1. Configuration action
2. Create a JSP file HelloWorld.jsp
3. Creating HelloWorld.java

1. Configuration action
The struts.xml the package label, write the following action

<!-- hello action -->
                <action name="helloworld">
                        <result>/WEB-INF/HelloWorld.jsp</result>
                </action>

2. Create a JSP file HelloWorld.jsp
In the WEB-INF directory, create a HelloWorld.jsp, to use the Struts tag, it is necessary to introduce tag library, in the file at the beginning of the preparation:

<%@ taglib prefix="s" uri="/struts-tags"%>

html The body says:

<body>
    Hello World! This is the first JSP page!<br>
    <br/>
    <s:property value="message"/>
  </body>

3. Creating HelloWorld.java
In the package path com.hust.wdp.helloworld, create HelloWorld.java. Code is as follows:

package com.hust.wdp.helloworld;

import com.opensymphony.xwork2.ActionSupport;

public class HelloWorld extends ActionSupport {
        /**
         *
         */
        private static final long serialVersionUID = 5351576682976847552L;
        private String message = "Hello World! Struts2 is taking function!";

        @Override
        public String execute() throws Exception {
                // TODO Auto-generated method stub
                this.setMessage(message);
                return SUCCESS;
        }

        public String getMessage() {
                return message;
        }
        public void setMessage(String message) {
                this.message = message;
        }
}

4. Test <br /> in MyEclipse to start tomcat, in the browser, enter http://localhost:8080/wdpweb/helloworld.action, which see the following results:
Hello World! This is the first JSP page!
Hello World! Struts2 is taking function!
Note: in the browser address of the wdp for the project name, since all the web project tomcat will be deployed in the webapps directory of its own, so url should appear in the "/ wdpweb" path, if the above package label are defined namespace, be admitted url appears in "/ wdpweb / namespace".

相关文章
  • 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 Integration Series 2 - The Struts2.1.8.1 integrating Spring3.0.1 2009-02-14

    As Spring3.0 version and previous version is a major division point. So, there are a lot of changes, where the mere enunciation of an integrated approach, study its new use. 1. The introduction of spring of the jar package 2. Create a Spring configur

  • SSH Integration Series 1 2010-03-24

    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

  • My SSH integration (spring management of Action) 2010-03-25

    My SSH integrated version are: spring2.0 Struts1.3 Hibernate3.2, Myeclipse version is 6.01. (This article is only to record their steps and for the integration of SSH, in the middle there will be a lot of mistakes, if not want to be misled, or not re

  • ssh integration exception summary Cannot locate the chosen ObjectFactory implementation: spring 2010-09-18

    ssh integration exception summary Cannot locate the chosen ObjectFactory implementation: spring Struts2 An error : Exception starting filter struts2 Cannot locate the chosen ObjectFactory implementation: spring - [unknown location] at org.apache.stru

  • SSH framework of the configuration steps 2010-11-25

    Reprinted: http://haiyang08101.javaeye.com/blog/816272 Core Tip: It is now developing a project using S2SH framework, configure the environment with a day or two, and now the environment was configured to write to the document issued under the order,

  • chapter06 SSH integration 2010-04-07

    chapter06 SSH integration 1, SSH: Struts (layer) + Spring (business layer) + Hibernate (Persistence) Struts: Struts is a presentation layer framework, the main role is to interface display, receiving the request, the request distribution. In the MVC

  • SSH integration jBPM4.3 to note 2010-07-08

    SSH integration jBPM4.3 several issues you should pay attention to use jBPM4.3, first of all you have to understand at least 1.UML2.0 the activity diagram (since jBPM is the Activity Diagram Model) 2.Hibernate (jBPM integration for Hibernate as the e

  • Spring integration with Hibernate configuration 2009-06-23

    Spring integration with Hibernate configuration

  • struts2 2.1 that can remove the suffix (. action. do) access to 2.0 need to configure before they can be. 2010-06-24

    1.struts2 2.1 that can remove the suffix (. Action. Do) access to 2.0 need to configure before they can be. 2. <constant Name="struts.devMode" value="true" /> modify the configuration file without restarting the server

  • SSH integration of series 2 - the integration of Spring3.0.3 in Struts2.1.8.1 2010-07-08

    Since: http://scorpiomiracle.javaeye.com/blog/615635 As Spring3.0 version and the previous version is a major division point. So many changes, there is only elaborated an integrated approach, not of its new use. 1. The introduction of spring in the j

  • ssh integration of configuration and jar packages 2010-03-29

    1. Integration Spring and Hiberante <? xml version = "1.0" encoding = "UTF-8"?> <beans xmlns = "http://www.springframework.org/schema/beans" xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" xmlns: c

  • SSH integration of the main configuration file reference 1 2010-12-28

    First is the web.xml configuration file: <? Xml version = "1.0" encoding = "GBK"?> <Web-app version = "2.5" xmlns = "http://java.sun.com/xml/ns/javaee" xmlns: xsi = "http://www.w3.org/2001/XMLSchema-in

  • SSH integration of 2 main configuration file reference 2010-12-28

    The last one is more important spring configuration file applicationContext.xml: <? Xml version = "1.0" encoding = "GBK"?> <Beans xmlns = "http://www.springframework.org/schema/beans" xmlns: xsi = "http://www.w3

  • ssh Integration Configuration 2010-03-29

    web.xml file <?xml version="1.0" encoding="UTF-8"?> <web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="ht

  • SSH integration framework to connect Oracle database configuration 2010-03-31

    Recent research Struts + Spring + Hibernate framework integrated project, to collect information either. I will continue to publish outstanding representative, I hope you pay close attention to colleagues. The following attachment is the MVC framewor

  • 20100102 SSH integration of the log 2011-01-02

    SSH Configurations 14:53 2011-1-2 ------------------------------------------------------------ Construction hibernate.hbm.xml 1myeclipse - hibernate ibm db2(Universal driver) 2mye-spring Select package ( Conflict, leaving only one package asm2.23 uti

  • SSH integration 2009-06-22

    Web.xml is the first choice to create the ActionServlet and Struts configuration Spring filter characters <? xml version = "1.0" encoding = "UTF-8"?> <web-app xmlns = " http://java.sun.com/xml/ns/j2ee "Xmlns: xsi =&q

  • Struts Spring Hibernate (SSH) integration example 2009-08-12

    http://www.blogjava.net/action/archive/2009/04/09/140566.html Web.xml is the first choice to create the ActionServlet and Struts configuration Spring filter characters <? xml version = "1.0" encoding = "UTF-8"?> <web-app xmlns

  • [Change] based on the SSH integration MyEclipse6.5 2010-03-29

    1. The preparation of purpose In order to integrate people who want to learn the few detours!!! 2. Experimental environment l MyEclipse6.5 l Tomcat5.5.26 l MySQL5.0 l database script CREATE TABLE user ( id int (11) NOT NULL auto_increment, username v