form 表单中form action属性是用来干什么的

1583人阅读
java(10)
&1、ActionForm的作用机理
2.ActionForm的用法
&& a.首先创建ActionForm
&&&&&&&& import org.apache.struts.action.*;
&&&&&&&& import javax.servlet.http.*;
&&&&&&&& public class TestActionForm extends ActionForm{
&&&&&&&&&&&&&&&//属性值 ,下面username,password假设作为该类的属性
&&&&&&&&&&&&&& &&
&&&&&&&&&&&&&& //setter和getter方法
&&&&&&&&&&&&&& &&
&&&&&&&&&&&&&& //验证表单数据,使用ActionErrors和ActionMessage来提交错误信息到页面
&&&&&&&&&&&&&& public ActionErrors validate(ActionMapping actionMapping,HttpServletRequest httpServletRequest)
&&&&&&&&&&&&&& {
&&&&&&&&&&&&&&&&& //ActionErrors封装一组验证错误,同map类似
&&&&&&&&&&&&&&&&& ActionErrors errors=new ActionErrors();
&&&&&&&&&&&&&&&&& errors.add("nameError",new ActionMessage("error.username.required",username));
&&&&&&&&&&&&&&&&& errors.add("passwordError",new ActionMessage("error.username.required",password));
&&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&}
&&&&&&&&&&&&&& //表单数据复位
&&&&&&&&&&&&&& public void reset(ActionMapping actionMapping,HttpServletRequest httpServletRequest)
&&&&&&&&&&&&&& {
&&&&&&&&&&&&&& }
&&&&&&&& }
&& b.配置ActionForm
&&&&&&&&&每创建一个ActionForm类,就需要在Struts的配置文件Struts-config.xml中配置这个类。
&&&&&&&& &form-beans&
&&&&&&&&&&&&&&&&& &form-bean name="testActionForm" type="test.TestActionForm"&&/form-bean&
&&&&&&&& &/form-beans&
&&&c.访问ActionForm
&&&&&&&& 1)使用Struts HTML标记库
&&&&&&&& 2)从Request或session对象中取出ActionForm对象
&&&&&&&&&&&&&&&&& TestActionForm form=(TestActionForm)request.getAttribute("testActionForm");
&&&&&&&& 3)通过Action类的execute()方法直接访问ActionForm
3.表单数据的验证
&&&a.重写validate()方法
&&&&&&&&&&&&&&//验证表单数据,使用ActionErrors和ActionMessage来提交错误信息到页面
&&&&&&&&&&&&&& public ActionErrors validate(ActionMapping actionMapping,HttpServletRequest httpServletRequest)
&&&&&&&&&&&&&& {
&&&&&&&&&&&&&&&&& //ActionErrors封装一组验证错误,同map类似
&&&&&&&&&&&&&&&&& ActionErrors errors=new ActionErrors();
&&&&&&&&&&&&&&&&& errors.add("nameError",new ActionMessage("error.username.required",username));
&&&&&&&&&&&&&&&&& errors.add("passwordError",new ActionMessage("error.username.required",password));
&&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&}
&&&b.设置资源文件
&&&&&&&&&&&&&& #username is wrong用户名有误&&&&&&&&&&&&&& error.username.required=&li&username is wrong&/li&&&&&&&&&&&&&&& #password is wrong&&&&&&&&&&&&&& error.password.required=&li&password is wrong&/li&
&&&c.修改配置文件
&&&&&&&&&&&&&& 在struts-config.xml配置文件中,把&action&元素的validate属性设置为true,指定input属性的URL值(当表单验证失败的时候返回该URL);并添加&message-resources&元素以指定资源文件的存放路径。
&&&&&&&&&&&&&& 可以通过配置web.xml来配置ActionServlet显示的文件后缀,红色部分:
&&&&&&&&&&&&&&&& &servlet-mapping&&&&&&&&&&&&&&&&&&& &servlet-name&action&/servlet-name&&&&&&&&&&&&&&&&&&& &url-pattern&*.aspx&/url-pattern&&&&&&&&&&&&&&&&& &/servlet-mapping&
&&&d.输入页面中插入标记
&&&&&&&&&&&&&& &html:errors property="namewrong"/&
4.编程时需要注意的一些小问题:
&&&&&&&&&&&&&& &html:form action="loginForm" method="post"&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&& &!--一些html代码--&
&&&&&&&&&&&&&& &/html:form&
&&&&&&&&&&&&&& struts-config.xml中的配置:
&&&&&&&&&&&&&& &form-beans&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&& &form-bean name="loginForm" type="struts.LoginForm"&&/form-bean&
&&&&&&&&&&&&&& &/form-beans&
&&&&&&&&&&&&&&&&action-mappings&&&&&&&&&&&&&&&&&&& &action path="/loginForm" name="loginForm" type="struts.LoginAction" scope="request" validate="true" input="/login.jsp" attribute="loginForm"&&&&&&&&&&&&&&&&&&& &/action&&&&&&&&&&&&&&&&& &/action-mappings&
&&&&&&&&&&&&&&&&红色与红色部分名称一样,蓝色与蓝色部分名称一样,可以随意命名,但是名字相互对应!!
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:42960次
排名:千里之外form action中get \post传递参数的问题
form action中get \post传递参数的问题
XML/HTML code12345&form&action="servlet/ThirdServlet?userName=1&passWord=2"&method="post"&&&&&&&&&&&姓名&input&type="text"&name="uesrName"&&br&&&&&&&&&&&密码&input&type="text"&name="passWord"&&br&&&&&&&&&&&&input&type="submit"&value="提交"&&&&/form&&&Java code123567public&void&doPost(HttpServletRequest&request,&HttpServletResponse&response)&&&&&&&&&&&&&&throws&ServletException,&IOException&{&&&&&&&&&&String&userName&=&request.getParameter("userName");&&&&&&&&&&String&passWord&=&request.getParameter("passWord");&&&&&&&&&&response.getWriter().println("userName&---&"+userName);&&&&&&&&&&response.getWriter().println("passWord----&"+passWord);&&}&当form提交方式为get的时候,组件里填写了value的值,action里的url后也带有参数(写死的),这时servlet获取的uesrName和passWord是文本组件里的值当form提交方式为post的时候,组件里填写了value的值,action里的url后也带有参数(写死的),这时servlet获取的uesrName和passWord是url后参数的值表单提交中Get和Post方式的区别有5点1.get是从服务器上获取数据,post是向服务器传送数据。2.get是把参数数据队列加到提交表单的ACTION属性所指的URL中,值和表单内各个字段一一对应,在URL中可以看到。post是通过HTTPpost机制,将表单内各个字段与其内容放置在HTML HEADER内一起传送到ACTION属性所指的URL地址。用户看不到这个过程。3.对于get方式,服务器端用Request.QueryString获取变量的值,对于post方式,服务器端用Request.Form获取提交的数据。4.get传送的数据量较小,不能大于2KB。post传送的数据量较大,一般被默认为不受限制。但理论上,IIS4中最大量为80KB,IIS5中为100KB。5.get安全性非常低,post安全性较高。
发表评论:
TA的最新馆藏[转]&二次元同好交流新大陆
扫码下载App
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!&&|&&
LOFTER精选
网易考拉推荐
用微信&&“扫一扫”
将文章分享到朋友圈。
用易信&&“扫一扫”
将文章分享到朋友圈。
阅读(2433)|
用微信&&“扫一扫”
将文章分享到朋友圈。
用易信&&“扫一扫”
将文章分享到朋友圈。
历史上的今天
loftPermalink:'',
id:'fks_',
blogTitle:'form中采用图片作为提交按钮',
blogAbstract:'
有时候为了达到比较好的视觉效果,有人会使用图片代替按钮来提交或者重置表单数据。方式一:&FORM name=\"formName\" action=\"xxxx\" &&INPUT name=\"textfield2\"&&INPUT type=\"image\" height=19 width=53 src=\"xxx.gif\" align=absMiddle border=0 name=RedImg onclick=\"this.form.submit()\"&&INPUT type=image height=19 width=53 src=\"xxx.gif\" align=absMiddle border=0 name=RedImg3 onclick=\"this.form.reset()\"&',
blogTag:'',
blogUrl:'blog/static/',
isPublished:1,
istop:false,
modifyTime:0,
publishTime:7,
permalink:'blog/static/',
commentCount:0,
mainCommentCount:0,
recommendCount:14,
bsrk:-100,
publisherId:0,
recomBlogHome:false,
currentRecomBlog:false,
attachmentsFileIds:[],
groupInfo:{},
friendstatus:'none',
followstatus:'unFollow',
pubSucc:'',
visitorProvince:'',
visitorCity:'',
visitorNewUser:false,
postAddInfo:{},
mset:'000',
remindgoodnightblog:false,
isBlackVisitor:false,
isShowYodaoAd:false,
hostIntro:'',
hmcon:'0',
selfRecomBlogCount:'0',
lofter_single:''
{list a as x}
{if x.moveFrom=='wap'}
{elseif x.moveFrom=='iphone'}
{elseif x.moveFrom=='android'}
{elseif x.moveFrom=='mobile'}
${a.selfIntro|escape}{if great260}${suplement}{/if}
{list a as x}
推荐过这篇日志的人:
{list a as x}
{if !!b&&b.length>0}
他们还推荐了:
{list b as y}
转载记录:
{list d as x}
{list a as x}
{list a as x}
{list a as x}
{list a as x}
{if x_index>4}{break}{/if}
${fn2(x.publishTime,'yyyy-MM-dd HH:mm:ss')}
{list a as x}
{if !!(blogDetail.preBlogPermalink)}
{if !!(blogDetail.nextBlogPermalink)}
{list a as x}
{if defined('newslist')&&newslist.length>0}
{list newslist as x}
{if x_index>7}{break}{/if}
{list a as x}
{var first_option =}
{list x.voteDetailList as voteToOption}
{if voteToOption==1}
{if first_option==false},{/if}&&“${b[voteToOption_index]}”&&
{if (x.role!="-1") },“我是${c[x.role]}”&&{/if}
&&&&&&&&${fn1(x.voteTime)}
{if x.userName==''}{/if}
网易公司版权所有&&
{list x.l as y}
{if defined('wl')}
{list wl as x}{/list}一、form里面的action和method的post使用方法
&%@ Page Language="C#" AutoEventWireup="true" CodeFile="formsubmitpost.aspx.cs" Inherits="formsubmitpost" %&
&!DOCTYPE html&
&html xmlns="http://www.w3.org/1999/xhtml"&
&head runat="server"&
&meta http-equiv="Content-Type" content="text/ charset=utf-8"/&
&title&&/title&
&form id="form1" runat="server" action="formsubmitget.aspx" method="post"&
&input id="b" name="b" value="123" /&
id="w" type="submit" /&
当你点击button按钮提交的时候,浏览器的地址为http://localhost:1621/formsubmitpost.aspx,页面会刷新但是地址不变
二、form里面的action和method的get使用方法
&%@ Page Language="C#" AutoEventWireup="true" CodeFile="formsubmitget.aspx.cs" Inherits="formsubmitget" %&
&!DOCTYPE html&
&html xmlns="http://www.w3.org/1999/xhtml"&
&head runat="server"&
&meta http-equiv="Content-Type" content="text/ charset=utf-8"/&
&title&&/title&
&form id="form1" runat="server" action="formsubmitget.aspx" method="get"&
&input id="a" name="a" value="123" /&
id="w" type="submit" /&
但你点击button提交的时候,浏览器地址为http://localhost:1621/formsubmitget.aspx?__VIEWSTATE=%2FwEPDwUKLTEzNDM3NzkxOWRkeBFIL8xbs6u8bVKlOO5sf6FSAk0OTJ6ZUC4n2AN9oe4%3D&a=123&__VIEWSTATEGENERATOR=4B2C1984
而这个地址包含你传过去的值。
综上,用post不会显示传值,则post比较安全
阅读(...) 评论()<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
您的访问请求被拒绝 403 Forbidden - ITeye技术社区
您的访问请求被拒绝
亲爱的会员,您的IP地址所在网段被ITeye拒绝服务,这可能是以下两种情况导致:
一、您所在的网段内有网络爬虫大量抓取ITeye网页,为保证其他人流畅的访问ITeye,该网段被ITeye拒绝
二、您通过某个代理服务器访问ITeye网站,该代理服务器被网络爬虫利用,大量抓取ITeye网页
请您点击按钮解除封锁&}

我要回帖

更多关于 form action属性 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信