struts2 Action获取表单数据

1.通过属性驱动式  

 

1.首先设置 表单中的数据的name值 如:<input type="text" name="username" value="">
2.你用的是struts2,那么就在java类中写一个变量:变量名和页面上的name值一致 并有这个变量的get 和set方法 ,这样就能取到值了。

[html] view plaincopy
  1. <form action="sys/login.action" method="post">    
  2.     <input type="text" name="username">    
  3.     <input type="submit" value="submit">    
  4. </form>  


Action:直接通过get、set方法获取。

[java] view plaincopy
  1. public class sysAction extends ActionSupport{    
  2.     private String username;    
  3.    
  4.     public String login() throws Exception {    
  5.         System.out.println(username);    
  6.         return SUCCESS;    
  7.     }    
  8.    
  9.     public String getUsername() {    
  10.         return username;    
  11.     }    
  12.     public void setUsername(String username) {    
  13.         this.username= username;    
  14.     }    
  15. }     


2.模型驱动方式,必须要实现ModelDriven<T>接口。对于要传入多个model第二种方式不方便  

[html] view plaincopy
  1. <form action="sys/login.action" method="post">    
  2.     <input type="text" name="username">    
  3.     <input type="submit" value="submit">    
  4. </form>          

 


Action:必须实现getModel() 方法

 

[java] view plaincopy
  1. public class sysAction extends ActionSupport implements ModelDriven<User>{    
  2.     private User user;    
  3.    
  4.     public String login() throws Exception {    
  5.         System.out.println(getModel().getUsername());    
  6.         return SUCCESS;    
  7.     }    
  8.    
  9.     public User getModel() {    
  10.         if (null == user) {    
  11.             return user = new User();    
  12.         }    
  13.         return user;    
  14.     }    
  15. }     

 


3.第三种方式可以完全不实现ModelDriven<T>,也可使用多个model对象的属性。

 

[html] view plaincopy
  1. <form action="sys/login.action" method="post">    
  2.     <input type="text" name="user.username">    
  3.     <input type="text" name="teacher.level">    
  4.     <input type="submit" value="submit">    
  5. </form>    

 


Action: 必须提供set方法

[java] view plaincopy
  1. public class sysAction extends ActionSupport{    
  2.     private User user;    
  3.     private Teacher teacher;    
  4.    
  5.     public String login() throws Exception {    
  6.         System.out.println(user.getUsername());    
  7.         System.out.println(teacher.getLevel());    
  8.         return SUCCESS;    
  9.     }    
  10.    
  11.     public void setUser(User user) {    
  12.         this.user = user;    
  13.     }    
  14.     public void setTeacher(Teacher teacher) {    
  15.         this.teacher = teacher;    
  16.     }    
  17. }    

转载于:https://www.cnblogs.com/baoendemao/p/3804774.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/260524.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

python 计算器 eval ctf_CTF逆向--.NET与Python篇

题目(来源&#xff1a;Jarvis-OJ)&#xff1a;Classical CrackmeClassical CrackMe2FindKeyLoginClassical Crackme首先查壳没有壳&#xff0c;不过发现这是一个.net的程序&#xff0c;将其拖进dnSpy中&#xff0c;找到主程序&#xff0c;同时发现关键代码&#xff0c;如下所示…

2016年秋季个人阅读计划

阅读书目&#xff1a;《软件需求十步走》 读后感发表日期&#xff1a;阅读书目&#xff1a;《用户故事与敏捷方法》 读后感发表日期&#xff1a;第一篇&#xff1a;10月1日 第二篇&#xff1a;10月3日 第三篇&#xff1a;10月7日 第四篇&#xff1a;10月15日 第五篇&#xff1a…

第10章 Python 数字图像处理(DIP) - 图像分割 基础知识 标准差分割法

This Chapter is all about image segmentation. I still not finished whole chapter, but here try to publish some for reference. 这里写目录标题基础知识import sys import numpy as np import cv2 import matplotlib import matplotlib.pyplot as plt import PIL from …

OFBiz的探索进阶

主要参照https://cwiki.apache.org/OFBIZ/ofbiz-tutorial-a-beginners-development-guide.html这个教程&#xff0c;实现的过程教程上很详细&#xff0c;故这里不多说 还参考了下http://www.hotwaxmedia.com/apache-ofbiz-blog/ofbiz/ofbiz-tutorials/ofbiz-tutorial-building-…

python3语法都相同吗_python2 与 python3 语法区别--转

原文地址&#xff1a;http://old.sebug.net/paper/books/dive-into-python3/porting-code-to-python-3-with-2to3.html 使用2to3将代码移植到Python 3 ❝ Life is pleasant. Death is peaceful. It’s the transition that’s troublesome. ❞ — Isaac Asimov (attributed) 概…

对GCD的一些理解和实践

对GCD的一些理解和实践GCD GCD&#xff0c;全程Grand Central Dispatch&#xff0c;是苹果为了多核并行提出的解决方案。它是使用C语言实现&#xff0c;但是由于用了block来处理回调&#xff0c;所以使用起来十分方便。并且GCD会自动管理线程的生命周期&#xff0c;不需要我们去…

python scrapy爬虫遇见301_在Pycharm中运行Scrapy爬虫项目的基本操作

目标在Win7上建立一个Scrapy爬虫项目&#xff0c;以及对其进行基本操作。运行环境&#xff1a;电脑上已经安装了python(环境变量path已经设置好)&#xff0c;以及scrapy模块&#xff0c;IDE为Pycharm 。操作如下&#xff1a;一、建立Scrapy模板。进入自己的工作目录&#xff0c…

[Buzz Today]2012.08.08

# Dark Reign 2 源代码现身Google Code Pandemic工作室开发的即时战略游戏《Dark Reign 2》源代码被泄露到了Google Code http://code.google.com/p/darkreign2/ # Warsow 1.0发布 Set in a futuristic cartoonish world, Warsow is a completely free fast-paced first-person…

PyTorch训练中Dataset多线程加载数据,比Dataloader里设置多个workers还要快

PyTorch训练中Dataset多线程加载数据&#xff0c;而不是在DataLoader 背景与需求 现在做深度学习的越来越多人都有用PyTorch&#xff0c;他容易上手&#xff0c;而且API相对TF友好的不要太多。今天就给大家带来最近PyTorch训练的一些小小的心得。 大家做机器学习、深度学习都…

Trading

http://v.youku.com/v_show/id_XMTA0OTcxMjgw.html?fromy1.2-1-87.3.8-1.1-1-1-7 转载于:https://www.cnblogs.com/wangjianping/p/3705524.html

算法9---二叉树的遍历不用栈和递归

二叉树的遍历不用栈和递归 转自&#xff1a;ACM之家 http://www.acmerblog.com/inorder-tree-traversal-without-recursion-and-without-stack-5988.html我们知道&#xff0c;在深度搜索遍历的过程中&#xff0c;之所以要用递归或者是用非递归的栈方式&#xff0c;参考二叉树非…

python调用摄像头人脸识别代码_利用face_recognition,dlib与OpenCV调用摄像头进行人脸识别...

用已经搭建好 face_recognition&#xff0c;dlib 环境来进行人脸识别 未搭建好环境请参考&#xff1a; 使用opencv 调用摄像头 import face_recognition import cv2 video_capture cv2.videocapture(0) # videocapture打开摄像头&#xff0c;0为笔记本内置摄像头&#xff0c;1…

python列表批量 修改_python实现多进程按序号批量修改文件名的方法示例

本文实例讲述了python实现多进程按序号批量修改文件名的方法。分享给大家供大家参考&#xff0c;具体如下&#xff1a;说明文件名命名方式如图&#xff0c;是数字序号开头&#xff0c;但是中间有些文件删掉了&#xff0c;序号不连续&#xff0c;这里将序号连续起来&#xff0c;…

Struts1 tag

标签库&#xff1a; a) struts框架下的struts标签库 b) sun jstl c标签库 作用: 1) jsp 和 java代码分离 -- 自定义标签 用标签来替代Java的代码 2) struts标签 能够和struts-config.xml actionForm等特有的对象进行交互 stru…

“multiprocessing\spawn.py”, line 105, in spawn_main错误与解决方法

记录一个不知名的错误错误解决方法OS&#xff1a; Windows 10 错误非常的长&#xff0c;以至于&#xff0c;我也没有什么耐心去看&#xff0c;看了前面几行&#xff0c;应该是多线程引起的。下面太长&#xff0c;可以选择不看。 错误 Traceback (most recent call last): Trac…

hpunix下11gRac的安装

一.检查环境 1.操作系统版本# uname -a 2.补丁包三大补丁包#swlist -l bundle|grep QPKAPPS#swlist -l bundle|grep QPKBASE#swlist -l bundle|grep HWEnable11i #swlist -l patch -a supersedes|grep PHKL_XXXXX检查是否已有或是已被替代For HP-UX 11i V3 (11.31): PHCO_40381…

【转】彻底搞清计算结构体大小和数据对齐原则

数据对齐: 许多计算机系统对基本数据类型合法地址做出了一些限制&#xff0c;要求某种类型对象的地址必须是某个值K(通常是2&#xff0c;4或8)的倍数。这种对齐限制简化了形成处理器和存储器系统之间的接口的硬件设计。例如&#xff0c;假设一个处理器总是从存储器中取出8个字节…

python里pip是什么意思_python使用pip的方法是什么

python使用pip的方法是什么 发布时间&#xff1a;2020-08-25 11:51:08 来源&#xff1a;亿速云 阅读&#xff1a;104 作者&#xff1a;小新 小编给大家分享一下python使用pip的方法是什么&#xff0c;相信大部分人都还不怎么了解&#xff0c;因此分享这篇文章给大家参考一下&am…

Pytorch 学习率衰减 之 余弦退火与余弦warmup 自定义学习率衰减scheduler

学习率衰减&#xff0c;通常我们英文也叫做scheduler。本文学习率衰减自定义&#xff0c;通过2种方法实现自定义&#xff0c;一是利用lambda&#xff0c;另外一个是继承pytorch的lr_scheduler import math import matplotlib.pyplot as plt import numpy as np import torch i…

c++ 字符串赋给另一个_7.2 C++字符串处理函数

点击上方“C语言入门到精通”&#xff0c;选择置顶第一时间关注程序猿身边的故事作者闫小林白天搬砖&#xff0c;晚上做梦。我有故事&#xff0c;你有酒么&#xff1f;C字符串处理函数C语言和C提供了一些字符串函数&#xff0c;使得用户能很方便地对字符串进行处理。这些是放在…