Web Application File Structure
/WebContent/
/WebContent/META-INF/
/WebContent/WEB-INF/
/WebContent/WEB-INF/classes/struts.xml
/WebContent/WEB-INF/lib/
/WebContent/WEB-INF/lib/minimum JARs + any plugin JARs + plugin dependencies
/WebContent/WEB-INF/web.xml
See the structure as below -
The following files are a minium requirement for your application.
| Filename | Description |
|---|---|
| struts2-core.jar | Framework library itself, found in distribution root directory |
| xwork.jar | XWork 2 library on which Struts 2 is built (version 2.0 or later) |
| ognl.jar | Object Graph Navigation Language (OGNL), the expression language used throughout the framework |
| freemarker.jar | All UI tag templates are written in Freemarker (also a good option for your own views) |
| commons-logging.jar | Commons logging, which the framework uses to support transparently logging to either Log4J or JDK 1.4+ |
| commons-fileupload.jar | The Commons FileUpload package makes it easy to add robust, high-performance, file upload capability to your servlets and web applications. |
| commons-io.jar | Commons IO is a library of utilities to assist with developing IO functionality. |
| web.xml | Java web application configuration file that defines the filters (and other components) for your web application |
| struts.xml | Framework configuration file that defines the actions, results, and interceptors for your application |
Copy to the WEB-INF/lib directory
- the required JARs
- any Struts plugin JARs,
- any plugin dependencies.
Create ../WEB-INF/classes/struts.xml -
/index.jsp /HelloWorld.jsp
Snip of web.xml -
My Application struts2 org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter struts2 /*
Action Class HelloWorld -
package com.mqin.struts2.demo;
import com.opensymphony.xwork2.ActionSupport;
public class HelloWorld extends ActionSupport {
public static final String MESSAGE = "Struts is up and running ...";
public String execute() throws Exception {
setMessage(MESSAGE);
return SUCCESS;
}
private String message;
public void setMessage(String message) {
this.message = message;
}
public String getMessage() {
return message;
}
}
Running Result -



No comments:
Post a Comment