struts2工程创建步骤
1.添加JAR包
commons-logging-1.0.4.jar
freemarker-2.3.13.jar
ognl-2.6.11.jar
struts2-core-2.1.7.jar
xwork-core-2.1.4.jar
commons-fileupload-1.2.1.jar
commons-io-1.3.2.jar
2.在web.xml配置文件中配置一个过滤器
<!-- 定义Struts 2的核心控制器:FilterDispatcher -->
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
3.创建一个Action
4.配置Action在struts.xml中
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.1.7//EN"
"http://struts.apache.org/dtds/struts-2.1.7.dtd">
<struts>
<package name="example" namespace="/example" extends="struts-default">
<action name="login" class="com.amaker.action.LoginAction">
<result name ="success">/success.jsp</result>
<result name ="input">/login.jsp</result>
</action>
</package>
</struts>
5.JSP调用
${tip }
<form name="f1" id="f1" action="<%=path %>/login.action" method="post">
<table border="0">
<tr>
<td>username:</td>
<td><input type="text" name="username" id="login"></td>
</tr>
<tr>
<td>Password:</td>
<td><input type="password" name="password" id="password"></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" value="login"></td>
</tr>
本文详细介绍Struts2项目的搭建过程,包括所需JAR包的添加、web.xml配置、Action创建及配置,以及JSP页面的基本设置。
471

被折叠的 条评论
为什么被折叠?



