1.helloworld.jsp
2.web.xml
3.lib下的jar包
commons-fileupload-1.2.1.jar
commons-logging.jar
freemarker-2.3.15.jar
ognl-2.7.3.jar
struts2-core-2.1.8.1.jar
xwork-core-2.1.6.jar
4.Action类
5.struts.xml
6.访问地址:http://localhost:8080/struts2/helloworld.action
<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>helloworld页面</title>
</head>
<body>
helloworld,struts2!
</body>
</html>
2.web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<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>
3.lib下的jar包
commons-fileupload-1.2.1.jar
commons-logging.jar
freemarker-2.3.15.jar
ognl-2.7.3.jar
struts2-core-2.1.8.1.jar
xwork-core-2.1.6.jar
4.Action类
package com.hitsoft.action;
public class HelloWorld{
public String execute() throws Exception {
return "success";
}
}
5.struts.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<!-- <!DOCTYPE struts SYSTEM "struts-2.0.dtd">加载本地的dtd文件 -->
<struts>
<package name="struts2" extends="struts-default">
<action name="helloworld" class="com.hitsoft.action.HelloWorldAction">
<result name="success">/hellworld.jsp</result>
</action>
</package>
</struts>
6.访问地址:http://localhost:8080/struts2/helloworld.action