Struts2 the problem of losing packets in the process of setting up basic environment

Source: Internet
Author: User

Take one of the simplest struts2 's Hello world as an example to illustrate it.


Struts2 is inherited from the Actionsupport class, so that one of the simplest Hello world is not missing the package of that class, That is to say, we can not lack of xwork-core-2.3.16.jar, because we want to build the framework is struts2, so we can not lack of struts2-core-2.3.16.jar, otherwise this is not struts2 framework.


In summary, an essential package file for a struts2 framework is:

Struts2-core-2.3.16.jar
Xwork-core-2.3.16.jar


The HelloWorld source code for the STRUTS2 framework is as follows:

Struts2test.java Source:

Package Com.test;import Com.opensymphony.xwork2.actionsupport;public class Struts2test extends actionsupport{@ Overridepublic String Execute () throws Exception {return SUCCESS;}}

Struts.xml Source:

<?xml version= "1.0" encoding= "UTF-8"? ><! DOCTYPE struts Public "-//apache software foundation//dtd struts Configuration 2.3//en" "http://struts.apache.org/dtds/ Struts-2.3.dtd "><struts><constant name=" Struts.devmode "value=" true "/><package name=" Default " extends= "Struts-default" ><action name= "Hello" class= "com.test.Struts2Test" ><result name= "Success" > /success.jsp</result></action></package> </struts>    

Web. XML Source:

<?xml version= "1.0" encoding= "UTF-8"? ><web-app id= "Webapp_9" version= "2.4" xmlns= "http://java.sun.com/xml/ Ns/j2ee "xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance "xsi:schemalocation=" http://java.sun.com/xml/ns/ Java http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd ">  <welcome-file-list>    <welcome-file >index.jsp</welcome-file>  </welcome-file-list>    <filter>  <filter-name> Struts2</filter-name>  <filter-class> Org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter  </filter-class>  </ filter>   <filter-mapping>  <filter-name>struts2</filter-name>  <url-pattern >/*</url-pattern>  </filter-mapping>  </web-app>

Index.jsp Source:

<%@ page language= "java" import= "java.util.*" pageencoding= "iso-8859-1"%><%string path = Request.getcontextpath (); String basepath = request.getscheme () + "://" +request.getservername () + ":" +request.getserverport () +path+ "/";%> 

Success.jsp Source:

<%@ page language= "java" import= "java.util.*" pageencoding= "iso-8859-1"%><%string path = Request.getcontextpath (); String basepath = request.getscheme () + "://" +request.getservername () + ":" +request.getserverport () +path+ "/";%> 

To run the program:


When the following error occurs:

Severity: Exception Starting filter Struts2java.lang.noclassdeffounderror:ognl/propertyaccessor

As prompted, this means that the missing package file is OGNL, so we're going to import the package:

Ognl-3.0.6.jar


Restart, continue running the program


When the following error occurs:

Severity: Dispatcher initialization failedjava.lang.RuntimeException:java.lang.reflect.InvocationTargetException

At the prompt, the error that occurs at this point is "dispatcher initialization failed", and the package that implements the feature is javassist, so the package is imported:

Javassist-3.11.0.ga.jar


Go on:


The error message at this point is:

Severity: Exception Starting filter Struts2java.lang.noclassdeffounderror:org/apache/commons/lang3/stringutils

According to the prompt, the problem is that there is no class found, and the class is stringutils, so we want to import the package file of the class, because the prompt said that the class in the Lang3 package, the package is Commons, so according to the prompt, we can easily find the following package, directly import.

Commons-lang3-3.1.jar


Continue running:


The error reported at this time is:

Warning: Could not create jarentryrevision for [jar:file:/c:/apache-tomcat-6.0.20/webapps/struts2test/web-inf/lib/ Struts2-core-2.3.16.jar]!java.lang.noclassdeffounderror:org/apache/commons/io/fileutils

As prompted, we need to import the package file as: Commons/io, that is, we need to import the package file as Commons-io, so the package file imported here is:

Commons-io-2.2.jar


Continue running:


According to the prompt, the error reported at this time is:

Critical: Dispatcher initialization failedunable to load configuration. -bean-jar:file:/c:/apache-tomcat-6.0.20/webapps/struts2test/web-inf/lib/struts2-core-2.3.16.jar!/ struts-default.xml:64:179

According to the prompt, the problem is still the previous "scheduler initialization Failed", at this time we should look at its second message, the first time "scheduler initialization Failed", the second line reported that the error is: "InvocationTargetException", and now appear " Scheduler initialization Failed ", the second line of error message is:" struts-default.xml:64:179 ", so that this time the report is not the same error last time, the package file needs to be imported:

Commons-fileupload-1.3.jar


Continue running:


The error message for this report is:

Critical: Dispatcher initialization failedunable to load configuration. -bean-jar:file:/c:/apache-tomcat-6.0.20/webapps/struts2test/web-inf/lib/struts2-core-2.3.16.jar!/ struts-default.xml:69:87


The amount ... It seems that the problem has not been resolved, but look at the second line of hints, the prompt is: struts-default.xml:69:87, that is, the error message is not the same as the earlier, that is, this is not a problem, the previous problem has been resolved, This is a new issue, and the imported package file is:

Freemarker-2.3.19.jar


To continue running the program:


The message at this point is: information:

Server Startup in 7228 MS,


This means that the program is now running without problems.


The next step is to access the program's path:

http://localhost:8080/Struts2Test/


Results of the operation:



When the access path is:

Http://localhost:8080/Struts2Test/hello

The result of this run is:








Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Struts2 the problem of losing packets in the process of setting up basic 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.