首页 > 其他 > 详细

SSH-Struts第一弹:ActionSupport类

时间:2014-03-17 12:26:04      阅读:556      评论:0      收藏:0      [点我收藏+]

Action继承了com.opensymphony.xwork2.ActionSupport

bubuko.com,布布扣
1 package com.candy.login;
2 import com.opensymphony.xwork2.ActionSupport;
3 public class LoginAction extends ActionSupport {}
View Code

继承了ActionSupport后,可以在execute()里加入以下验证信息:

bubuko.com,布布扣
1 addActionError(""); // Action错误提示
2    addFieldError("", ""); // 字段错误提示
3    addActionMessage(""); // 错误消息
View Code

 

同时,发下web.xml和struts.xml

web.xml:

bubuko.com,布布扣
 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <web-app id="WebApp_9" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
 3     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 4     xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
 5     <display-name>Struts</display-name>
 6     <filter>
 7         <filter-name>struts2</filter-name>
 8         <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
 9     </filter>
10     <filter-mapping>
11         <filter-name>struts2</filter-name>
12         <url-pattern>/*</url-pattern>
13     </filter-mapping>
14     <welcome-file-list>
15         <welcome-file>index.jsp</welcome-file>
16     </welcome-file-list>
17 </web-app>
18     
View Code

struts.xml:

bubuko.com,布布扣
 1 <?xml version="1.0" encoding="UTF-8" ?>
 2 <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN" "http://struts.apache.org/dtds/struts-2.3.dtd">
 3 <struts>
 4     <constant name="struts.i18n.encoding" value="UTF-8"></constant>
 5     <package name="struts2" extends="struts-default" namespace="/">
 6         <global-results>
 7             <result name="errorPath" type="redirect">
 8                 /errorPage.jsp
 9             </result>
10         </global-results>
11         <action name="LoginAction" class="com.candy.login.LoginAction">
12             <result name="error">index.jsp</result>
13             <result>/WEB-INF/main.jsp</result>
14         </action>
15     </package>
16 
17     <!-- 引用其他模块的Struts.xml配置文件 -->
18     <!-- <include file="testStruts.xml"/> -->
19 
20     <!-- Apache Struts2官方网站 -->
21     <!-- http://struts.apache.org/release/2.0.x/ -->
22 </struts>
View Code

SSH-Struts第二弹:一个Form提交两个Action

SSH-Struts第一弹:ActionSupport类,布布扣,bubuko.com

SSH-Struts第一弹:ActionSupport类

原文:http://www.cnblogs.com/Candies/p/3604148.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!