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

2020-02-28 其他范文 下载本文

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接收的三种方法.docx》
将本文的Word文档下载,方便收藏和打印
推荐度:
struts2中的jsp值传到后台action接收的三种方法
点击下载文档
相关专题 后台如何接收ajax传值 三种 后台 方法 后台如何接收ajax传值 三种 后台 方法
[其他范文]相关推荐
    [其他范文]热门文章
      下载全文