这个是struts.xml配置:只是简单的配置了<action>的name属性,以及<result>指向页面(/WEB-INF/pages/input.jsp)
<?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>
<package name="helloWord" extends="struts-default">
<action name="product-input">
<result>/WEB-INF/pages/input.jsp</result>
</action>
</package>
</struts>
下面的这个是web.xml配置信息 ,只需要将Struts2下载的文件中的web.xml中的部分扣下来即可!
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="starter" 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/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.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>
下面的是/WEB-INF/pages下的input.jsp页面
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'input.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<!--输入文本框以及提交按钮-->
<form action="product-save.action" method="post">
ProductName:<input type="text" name="productName"/><br/>
ProductDesc:<input type="text" name="productDesc"/><br/>
ProductPrice:<input type="text" name="productPrice"/><br/>
<input type="submit" value="submit"/>
</form>
</body>
</html>
再导入相应的jar包
就可以实现Struts2的简单例子了(如图)