Action中接收参数的方式
来源:互联网 发布:软件开发项目售后服务 编辑:程序博客网 时间:2024/05/18 00:10
在Action接收参数的方式有3种:
- 直接使用属性对应
- 使用对像接收
- 实现ModelDriven接口
index.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>Insert title here</title></head><body><h3>1.使用属性接收</h3><form action="user/common!login" method="post">name:<input type="text" name="name"/>password:<input type="password" name="password"/><input type="submit" value="login" /></form><h3>2.使用对象接收</h3><form action="user/common!login2" method="post">name:<input type="text" name="user.name"/>password:<input type="password" name="user.password"/><input type="submit" value="login" /></form><h3>2.实现ModelDriven接口</h3><form action="user/common!login3" method="post">name:<input type="text" name="name"/>password:<input type="password" name="password"/><input type="submit" value="login" /></form></body></html>
UserAction
package com.deppon.demo.struts;import com.deppon.demo.entity.UserEntity;import com.opensymphony.xwork2.ActionSupport;import com.opensymphony.xwork2.ModelDriven;public class UserAction extends ActionSupport implements ModelDriven<UserEntity>{private static final long serialVersionUID = 7146977447328113550L;private String name;private String password;private UserEntity user;private UserEntity userModel = new UserEntity();public UserEntity getModel() {return userModel;}public UserEntity getUser() {return user;}public void setUser(UserEntity user) {this.user = user;}public String getName() {return name;}public void setName(String name) {this.name = name;}public String getPassword() {return password;}public void setPassword(String password) {this.password = password;}/** * 使用属性的方式,直接接收参数 * 当参数较多时,不方便 * @return */public String login() {System.out.println("name->" + name + ",password->" + password);return SUCCESS;}/** * 使用对象接收 * 需要加前缀,和变量名一致 * @return */public String login2() {System.out.println("user->" + user);return SUCCESS;}/** * 是想ModelDriven接口 * @return */public String login3() {System.out.println("userModel->" + userModel);return SUCCESS;}}
UserEntity
package com.deppon.demo.entity;import java.io.Serializable;public class UserEntity implements Serializable {private static final long serialVersionUID = -1467621300783425180L;private String name;private String password;public String getName() {return name;}public void setName(String name) {this.name = name;}public String getPassword() {return password;}public void setPassword(String password) {this.password = password;}@Overridepublic String toString() {return "UserEntity [name=" + name + ", password=" + password + "]";}}
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"><struts><constant name="struts.i18n.encoding" value="utf-8"></constant><constant name="struts.multipart.maxSize" value="20971520"/> <constant name="struts.devMode" value="true" /> <package name="p_user" namespace="/user" extends="struts-default"> <action name="common" class="com.deppon.demo.struts.UserAction"> <result type="redirect">/index.jsp</result> </action> </package></struts>
- Action中接收参数的方式
- struts2在Action中接收参数的三种方式
- Struts2中Action接收参数的三种方式
- Struts2中Action接收参数的方法
- Struts2中Action接收参数的方法
- Struts2中Action接收参数的方法
- Struts2中Action接收参数的方法
- struts2中action接收参数的方法
- struts2中action接收参数的方法
- struts2中action接收参数的方法
- struts2中action接收参数的方法
- struts2中action接收参数的方法
- struts2中action接收参数的方法
- Struts2中Action接收参数的方法
- Struts2中Action接收传递的参数
- struts2中Action接收参数的方法
- struts2中action接收参数的方法
- Struts2中Action接收参数的方法
- App营销探秘:预装太花钱 口碑营销受宠
- java 页面传值日常笔记
- Oracle 11g安装图文攻略
- pthread_cancel用法及常见问题
- string、char*和字符串字面值的区别
- Action中接收参数的方式
- servlet 之forward和sendRedirect跳转
- 解决jsp页面元素使用disabled=true带来的不能传值到后台问题
- 手机网站的布局
- CentOS怎么从6.x升级到6.4最新版
- Android之Home键监听封装
- 关于面试时项目的介绍
- request.getParameter和request.getAttribute之间
- Oracle数据库DBA专题技术精粹