struts validate验证密码字符不合法,怎么把焦点设置在密码输入框上? 多谢,请问在那里设置onfocus?怎么设置?验证不合法后,会自动设置为onfocus吗? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 在body标签中加入onfocus="document.form1.password.focus()",当然也可以再写一个javascript函数,然后根据返回的值来判断要使哪一个输入框选中。 楼主是说struts1 还是struts2啊? struts1的话 你不用struts1的标签直接用html标签 当验证失败后它就不会保存你输入的内容login.jsp<%@ page language="java" pageEncoding="UTF-8"%><%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%> <%@ taglib uri="http://struts.apache.org/tags-html" prefix="html"%> <html> <head> <title>JSP for LoginForm form</title> </head> <body onload="document.loginForm.username.focus()"> <html:form action="/login" > 用户名<input type="text" name="username"/></br> 密码<input type="password" name="password"/></br> <input type="submit" value="提交"/> </html:form > </body></html>LoginForm public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) { ActionErrors errors=new ActionErrors(); if(this.getUsername()==null||this.getUsername()=="") { errors.add("username", new ActionMessage("用户名不能为空")); } if(this.getPassword()==null||this.getPassword()=="") { errors.add("password", new ActionMessage("密码不能为空")); } return errors; } stuts.config.xml <form-beans > <form-bean name="loginForm" type="com.yourcompany.struts.form.LoginForm" /> </form-beans> <action-mappings > <action attribute="loginForm" input="/login.jsp" name="loginForm" path="/login" scope="request" type="com.yourcompany.struts.action.LoginAction"> <forward name="success" path="/success.jsp" /> </action>loginAction public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { LoginForm loginForm = (LoginForm) form;// TODO Auto-generated method stub if(loginForm.getUsername().equals("CSDN")&&loginForm.getPassword().equals("CSDN")) { return mapping.findForward("success"); } return mapping.getInputForward(); } C客户端调用java webservice struct2如何使用ajax 客户端找不到服务器得问题,实在没有分了 如何配置tomcat+ActiveMQ?(希望能够提供详细配置) tomcat问题,求助高手中的高手 hibernate 库表对象模型的问题,有深度! srping为什么获取不到sessionFactory JMS的问题???? freemarker 中 样式 div 显示问题 在线视频,被下载后不能播放或者需要密码 我想请问一个关于安全的问题 struts 用动态表单 怎样设置 radio的默认选中啊,急啊急啊急啊急啊--先谢啦
login.jsp<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
<html>
<head>
<title>JSP for LoginForm form</title>
</head>
<body onload="document.loginForm.username.focus()">
<html:form action="/login" >
用户名<input type="text" name="username"/></br>
密码<input type="password" name="password"/></br>
<input type="submit" value="提交"/>
</html:form >
</body>
</html>LoginForm public ActionErrors validate(ActionMapping mapping,
HttpServletRequest request) {
ActionErrors errors=new ActionErrors();
if(this.getUsername()==null||this.getUsername()=="")
{
errors.add("username", new ActionMessage("用户名不能为空"));
} if(this.getPassword()==null||this.getPassword()=="")
{
errors.add("password", new ActionMessage("密码不能为空"));
}
return errors;
}
<form-bean name="loginForm" type="com.yourcompany.struts.form.LoginForm" />
</form-beans> <action-mappings >
<action
attribute="loginForm"
input="/login.jsp"
name="loginForm"
path="/login"
scope="request"
type="com.yourcompany.struts.action.LoginAction">
<forward name="success" path="/success.jsp" />
</action>
loginAction public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
LoginForm loginForm = (LoginForm) form;// TODO Auto-generated method stub
if(loginForm.getUsername().equals("CSDN")&&loginForm.getPassword().equals("CSDN"))
{
return mapping.findForward("success");
}
return mapping.getInputForward();
}