Struts1.2中的action配置(使用DynaActionForm)
来源:互联网 发布:大番长数据修改器 编辑:程序博客网 时间:2024/05/26 07:29
版本:eclipse 3.3,myeclipse 6.0,tomcat 6.0
在myeclipse中新建项目StrutsDemo,导入Struts1.2属性
在com.shiryu.action包中新建RegisterAction.java
package com.shiryu.action;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.DynaActionForm;
/**
* MyEclipse Struts
* Creation date: 10-06-2008
*
* XDoclet definition:
* @struts.action path="/register" name="registerForm"input="/register.jsp" scope="request"validate="true"
* @struts.action-forward name="wel" path="/wel.jsp"
* @struts.action-forward name="err" path="/err.jsp"
*/
public class RegisterAction extends Action {
/*
* Generated Methods
*/
/**
* Method execute
* @param mapping
* @param form
* @param request
* @param response
* @return ActionForward
*/
public ActionForward execute(ActionMapping mapping,ActionForm form,
HttpServletRequestrequest, HttpServletResponse response) {
DynaActionForm registerForm =(DynaActionForm) form;
String name= (String)registerForm.get("username");
request.setAttribute("name",name);
returnmapping.findForward("wel");
}
}
配置web.xml文件
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"version="2.4"xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
配置struts-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTDStruts Configuration 1.1//EN" "http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">
<struts-config>
<data-sources />
<form-beans >
<form-bean name="registerForm"type="org.apache.struts.action.DynaActionForm">
<form-property name="username"type="java.lang.String" />
<form-property name="password"type="java.lang.String" />
</form-bean>
</form-beans>
<global-exceptions />
<global-forwards />
<action-mappings >
<action
attribute="registerForm"
input="/register.jsp"
name="registerForm"
path="/register"
scope="request"
type="com.shiryu.action.RegisterAction">
</action>
</action-mappings>
<message-resources parameter="com.shiryu.ApplicationResources"/>
</struts-config>
新建register.jsp
<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-bean"prefix="bean"%>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-html"prefix="html"%>
<html>
<head>
<title>JSP for DynaActionFormform</title>
</head>
<body>
<html:formaction="/register">
<bean:message key="register.username" /><html:text property="username"/><html:errorsproperty="username"/><br/>
<bean:message key="register.password" /><html:passwordproperty="password"/><html:errorsproperty="password"/><br/>
<html:submit/><html:cancel/>
</html:form>
</body>
</html>
配置ApplicationResources.properties
register.username = username:
register.password = password:
- Struts1.2中的action配置(使用DynaActionForm)
- Struts1.2中的action配置
- 在struts1.2中的action路径内使用通配符
- Struts1.2中的Dispatch Action(给action传参数)配置
- struts1之LocaleAction、DynaActionForm
- struts1.2的action参数配置
- Struts1中的<action>标签
- Struts1中的<action>标签
- Struts1.2中ActionForm与ValidatorForm、DynaActionForm的区别
- Struts1.2中ActionForm与ValidatorForm、DynaActionForm的区别
- Struts1.2中的LookupDispatchAction配置
- Struts1.2中的MappingDispatchAction 配置
- Struts1.2中的MappingDispatchAction 配置
- struts1.x基本action的配置与使用
- struts1.x基本action的配置与使用
- Struts1.2中的资源文件的配置
- Struts中的DynaActionForm
- struts1+jquery+action+jsp基本配置总结
- Struts2.0入门
- debian 5.04 lenny 配置DNS服务器
- linux命令
- [转]新概念英语学习视频教程1-4册
- SD操作学习(转)
- Struts1.2中的action配置(使用DynaActionForm)
- 关于MYSQL 远程登录的授权方法 命令
- 非真实渲染(一)
- Maven antrun plugin调用Ant Optional Task
- servlet生命周期
- Ogre的设计模式分析之-单件模式
- 学习JAVA的步骤
- Gxxgle戒断综合症
- WaitForSingleObject 的讨论