One of the SSH integrations: add Struts2 environment

Source: Internet
Author: User

Before adding an environment, create a Web project in MyEclipse with the following project directory:

Description: The project is divided into three tiers: domain layer, service layer, view layer, SRC Decentralized java code, config Decentralization framework configuration file, lib file to decentralize the project required jar package.

    

1. The first building is the STRUTS2 environment:

  Version: Struts2.3.16.3

 The jar package used:

  

The configuration file used:

Add the filters required for struts in Web. xml:

1     <Filter>2         <Filter-name>Struts2</Filter-name>3         <Filter-class>Org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</Filter-class>4     </Filter>5 6     <filter-mapping>7         <Filter-name>Struts2</Filter-name>8         <Url-pattern>/*</Url-pattern>9     </filter-mapping>

Struts.xml:

1 <?XML version= "1.0" encoding= "UTF-8"?>2 <!DOCTYPE Struts public3 "-//apache software foundation//dtd Struts Configuration 2.3//en"4 "Http://struts.apache.org/dtds/struts-2.3.dtd">5 6 <Struts>7 8     <constantname= "Struts.enable.DynamicMethodInvocation"value= "false" />9     <!--Developer Mode -Ten     <constantname= "Struts.devmode"value= "true" /> One     <!--the extension is. Action - A     <constantname= "Struts.action.extension"value= "Action"></constant> -     <!--The front desk is set to Simple mode - -     <constantname= "Struts.ui.theme"value= "simple"></constant> the     < Packagename= "Default"namespace="/"extends= "Struts-default"> -  -          -     </ Package> +  - </Struts>

Log4j.properties:

# # log4j Settings for log4j 1.2.x (via Jakarta-commons-logging) # # The five logging levels used by Log is (in order): ##
   1. DEBUG (The Least serious) #   2. info#   3. warn#   4. error#   5. FATAL (the most serious) # Set root logger level to WARN and append to Stdoutlog4j.rootlogger=info, Stdoutlog4j.appender.st dout=org.apache.log4j.consoleappenderlog4j.appender.stdout.target=system.outlog4j.appender.stdout.layout= org.apache.log4j.patternlayout# Pattern to output the caller ' s file name and line number.log4j.appender.stdout.layout.conversionpattern=%d%5p (%c:%l)-%m%n# Print only messages of the level ERROR or above I n the package nomodule.log4j.logger.nomodule=fatallog4j.logger.com.opensymphony.xwork2= Debuglog4j.logger.org.apache.struts2=debug

To create a test Actiontest.java:

1  Packagecn.clear.web.test;2 3 ImportCom.opensymphony.xwork2.ActionSupport;4 5  Public classActiontestextendsactionsupport{6 7 8     /**9 * @fieldName: SerialversionuidTen * @fieldType: Long One * @Description: TODO A      */ -      -     Private Static Final LongSerialversionuid = 3248237427179914097L; the  -      PublicString Test ()throwsException { -  -          +         return"Success"; -     } +}

To create a test page test.jsp:

1 Import= "java.util.*" pageencoding= "UTF-8"%> 2  3 <! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" > 4  5   6     <title> test page </title> 7    8    9   <body> Ten     struts2 Environment added successfully!     </body> 

Add the action configuration code in Struts.xml:

1<?xml version= "1.0" encoding= "UTF-8"?>2<!DOCTYPE Struts public3"-//apache software foundation//dtd Struts Configuration 2.3//en"4"Http://struts.apache.org/dtds/struts-2.3.dtd" >5 6<struts>7 8<constant name= "Struts.enable.DynamicMethodInvocation" value= "false"/>9<!--developer Mode--Ten<constant name= "Struts.devmode" value= "true"/> One<!--extension. Action- A<constant name= "Struts.action.extension" value= "action" ></constant> -<!--front desk set to simple mode-- -<constant name= "Struts.ui.theme" value= "simple" ></constant> the< PackageName= "Default" namespace= "/"extends= "Struts-default" > -<!--test action-- -          <action name= "test" class= "Cn.clear.web.test.ActionTest" >  <result name= "s Uccess ">test.jsp</result>  </action>  -          +</ Package> A  at</struts>

Start the server, enter in the browser: http://localhost:8080/SSH/test.action, if you successfully go to the following page:

  

One of the SSH integrations: add Struts2 environment

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.