struts2中的jsp值传到后台action接收的三种方法_后台如何接收ajax传值

其他范文 时间:2020-02-28 04:29:45 收藏本文下载本文
【www.daodoc.com - 其他范文】

struts2中的jsp值传到后台action接收的三种方法由刀豆文库小编整理,希望给你工作、学习、生活带来方便,猜你可能喜欢“后台如何接收ajax传值”。

1.Action中的属性与表单中的属性一致就可以

JSP中的表单

用户名:

密码:

Action中的属性

publicclaLoginActionextends ActionSupport {

private String username;

private String paword;

public String getUsername(){

returnusername;}

publicvoid setUsername(String username){

this.username = username;}

public String getPaword(){

returnpaword;} publicvoid setPaword(String paword){

this.paword = paword;}

public String execute(){

if(username.equalsIgnoreCase(“aaa”)&&paword.equals(“aaaaaa”)){

returnSUCCESS;}

else{

returnERROR;} } }

2.使用一个VO类

在表单中提交的属性名改为user.username

用户名:

密码:

LoginAction中的属性改为user

publicclaLoginActionextends ActionSupport{ private User user;

public User getUser(){

returnuser;}

publicvoid setUser(User user){

this.user = user;}

public String execute(){

if(user.getUsername().equalsIgnoreCase(“aaa”)&&user.getPaword().equals(“aaaaaa”)){

returnSUCCESS;}

else{

returnERROR;} } }

3.使用Struts2中的ModelDriven数据模式

Action类要实现一个泛型接口,前台表单与1相同

publicclaLoginActionextends ActionSupport implements ModelDriven {

private User user = new User();

public String execute(){

if(user.getUsername().equalsIgnoreCase(“aaa”)&&user.getPaword().equals(“aaaaaa”)){

returnSUCCESS;}

else{

returnERROR;} }

public User getModel(){

returnuser;} }

下载struts2中的jsp值传到后台action接收的三种方法word格式文档
下载struts2中的jsp值传到后台action接收的三种方法.doc
将本文档下载到自己电脑,方便修改和收藏。
点此处下载文档

文档为doc格式

    热门文章
      整站推荐
        点击下载本文