当前位置:编程学习 > JAVA >>

struts2form表单提交值为一位数时后台获取不到

struts2 form表单提交值为一位数时后台获取不(一个数字 ,或者一个字母)

-------------------------------------------jsp--------------------------------------------
<%@ page language="java" import="java.util.*" pageEncoding="GBK"%>
<%@ page import="com.eipol.util.AppConfig" %>
<%@ taglib prefix="s" uri="/struts-tags"%> 
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gbk">
<title></title>
<link rel="stylesheet" href="<%=AppConfig.getProperty("cssHost")%>/common/common.css">
<link rel="stylesheet" href="<%=AppConfig.getProperty("cssHost")%>/ouchgzee_com/portal/v1.0/style/style.css">
<script type="text/javascript" src="<%=AppConfig.getProperty("cssHost")%>/common/js/jquery.js"></script>
<!--[if IE]>
<script type="text/javascript" src="<%=AppConfig.getProperty("cssHost")%>/common/js/resetHTML5_forIE.js"></script>
<![endif]-->
<!--[if lte IE 6]>
<script type="text/javascript" src="<%=AppConfig.getProperty("cssHost")%>/common/js/DD_belatedPNG_0.0.8a.js"></script>
<script type="text/javascript">
DD_belatedPNG.fix('.bg_png');
</script>
<![endif]--> 
<script type="text/javascript"> 
function checkInput(){
var b=$("#userName").val();
if(""==b){
alert("请输入用户名!");
return
}
var a=$("#password").val();
if(""==a){
alert("请输入密码!");
return
}
var c=$("#checkNumber").val();
if(""==c){
alert("请输入验证码!");
return
}
//document.getElementById("main").submit();
$("#user_type").val("1");
//alert("帐号或密码错误!");
//return;
//document.getElementById("main").submit();
//document.main.submit();
//$("#main").submit()
document.main.action = '/login.do?formMap.userType=1';
document.main.submit();
};
 
   function changeImg(){
document.getElementById("change").src="/image.jsp?w=80&h=30&s=28&"+Math.random();
   }
    
  function checkAutoLogin(){
  var d=document.cookie;
  var e=document.cookie.split(";");
  for(var c=0;c<e.length;c++){
  var a=e[c];
  var b=a.split("=");
  if("GZEDUN"==trimStr(b[0])){
  document.getElementById("userName").value=trimStr(b[1])
  }
  if("GZEDUP"==trimStr(b[0])){
  document.getElementById("password").value=trimStr(b[1])
  }
  if("GZEDUR"==trimStr(b[0])){
  document.getElementById("rempwd").checked="trimStr(ss[1])"
  }
  }
  };

function trimStr(str) { 
  var re = /\s*(\S[^\0]*\S)\s*/; 
  re.exec(str); 
  return RegExp.$1; 
  
}
    
     function  kibody() { if(event.keyCode ==13) checkInput(); }   
  
 
$(document).ready(function(){
checkAutoLogin();


}); 
 
//-->    
</script>
</head>
<body style="background:#fff;" onkeydown="kibody();">

<div class="wrap">
<div class="wrap_head"><img src="<%=AppConfig.getProperty("cssHost")%>/ouchgzee_com/portal/v1.0/images/logo.png" alt="" id="logo"  class="png"></div>
<div class="wrap_body">
<form action="/login.do"  method="post" name="main">
<input type="hidden" value="2" name="formMap.userType" id="user_type"/>
        <div class="loginArea">
            <div class="loginArea_head">
             <h1 id="loginTxt">学员请登录</h1>
            </div>
            <div class="loginArea_body">
            
             <table>
             <tbody>
             <tr>
             <td width="60" align="right">用户名:</td>
             <td><input type="text" class="loginArea_input" id="userName" name="formMap.account" style="height:12px;"/></td>
             </tr>
             <tr>
             <td width="60" align="right">密  码:</td>
             <td><input type="password" class="loginArea_input"  id="password" name="formMap.passWord" style="height:12px;"/></td>
             </tr>
             <tr>
             <td width="60" align="right">验证码:</td>
             <td><input type="text" class="loginArea_input"  id="checkNumber" name="formMap.verifycode" style="height:12px;"/></td>
             </tr>
             <tr>
             <td width="60" align="right"></td>
             <td>
               <img id="change" src="<%=request.getContextPath() %>/image.jsp?w=80&h=30&s=28"/>
               <a  onClick="changeImg();"  href="javascript:;">  看不清?换一张</a>
              </td>
             </tr>
             <tr>
             <td></td>
             <td><a href="javascript:checkInput();" class="btn_style03">
             <span class="loginArea_body_line" style="width:70px;text-align:center;">登录</span>  
             </a>
</td>
             </tr>
              <p>
                    

</p>
             </tbody>
             </table>
            </div>
            <div class="loginArea_foot"></div>
        </div>
</form>
</div>
  
  <!-- 页脚 -->
  <footer class="pro_edu_footer pro_edu_footer_bg top20 clearfix" style="border:1px solid #ededed;">
      
      <div class="footer_information">
          <div class="information_phone" style="line-height:22px;">
              <p class="footer_icon_01">服务热线:</p>
              <p class="top10"><span class="footer_phonecolor">020-969300    4000969300</span></p>
          </div>
          <div class="information_logo">
              <p class="clearfix bottom5"><span class="fl">国家开放大学(广州)版权所有</span><img class="bg_png fl margin_l25" src="<%=AppConfig.getProperty("cssHost")%>/ouchgzee_com/portal/v1.0/images/lhzx_logo.png" /></p>
              <p></p>
              <p>增值电信业务经营许可证编号粤B2-20042063 | 粤ICP备08131364号</p>
          </div>
      </div> 
  </footer>
  <!--//页脚-->

</div>
 
</body>
</html>
 
 

-------------------------------------------------action----------------------------
public String userLogin(){
//Object o = this.getRequest().getAttribute(arg0)
String userAccount = ObjectUtils.toString(formMap.get("account"));

String userType = ObjectUtils.toString(formMap.get("userType"));
String verifycode = ObjectUtils.toString(formMap.get("verifycode"), "");
if (null == verifycode || "".equals(verifycode.trim())) {
this.addFieldError("login.msg", "请输入验证码");
return errorPage(userType);

}
String rand = ObjectUtils.toString(request.getSession().getAttribute("rand"), "");
if (!verifycode.equals(rand)) {
this.addFieldError("login.msg", "登陆失败,验证码不一致");
return errorPage(userType);
}
formMap.put("initialPsw", ObjectUtils.toString(formMap.get("passWord")));
UserTo userInfoTo = userInfoService.userLogin(formMap);

if("1".equals(userType) && null == userInfoTo ){
//查找体验学员
formMap.put("userType", "5");
userInfoTo = userInfoService.userLogin(formMap);
if(userInfoTo == null){
//学员登陆 无信息 查询是否为学习卡用户
formMap.put("userType", "4"); 
userInfoTo = userInfoService.userLogin(formMap);
if(userInfoTo != null){
setSession(userInfoTo);
//学习卡用户登陆成功
return "cardUserLogin";
}

this.addFieldError("login.msg", "登陆失败,用户名或密码错误!");
return errorPage(userType);
}else{
setSession(userInfoTo);

return "toCenterStudy";
}
}


if (null == userInfoTo ) {
this.addFieldError("login.msg", "登陆失败,用户名或密码错误!");
return errorPage(userType);
}
setSession(userInfoTo);
if("1".equals(userType)){//学员
if ("2014200".equals(userAccount)) {
return "ys_Index";
}
return SUCCESS;
}else if("2".equals(userType)){//辅导教师
return "fudao";
}else if("3".equals(userType)){//班主任
return "bzr";
}

getRequest().getSession().setAttribute(com.eipol.util.SessionConstants.cardUserCasSessionInfo, userInfoTo);

return ERROR;
 
}
补充:Java ,  Java EE
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,