帮帮忙,为什么我的structs2 jquery ajax去做登录可是后台接收不到数据,这是关于毕业设计的,时间紧迫
这是jq代码
$(function() {
// alert("test");
$("#su").click(
function() {
// alert("test");
if ($("#username").val() != "" && $("#passw").val() != "") {
alert($("#username").val());
alert($("#passw").val());
$.ajax({
url : "user/logintest.action", //"user/logintest.action",
date : {
"username" : $("#username").val(),
"passw" : $("#passw").val(),
//'test' : "whl",
},
dataType : "json",
type : "post",
//async : false,
success : function(ok) {
if (ok) {
// alert("是否存在");
$("#login").css("display", "none");
$("#haslogin").css("display", "inline").html(
$("#email").val());
close_login();
} else {
$(".info").addClass(
"Validform_wrong Validform_checktip")
.html("用户名或密码错误!");
}
}
});
}
})
})
<div id="loginbg"></div>
<div id="v-login" style="display:none;">
<h2>
<span class="left">登录</span>
<span class="right v-login-close" onclick="close_login()"></span>
</h2>
<form class="login" method="post" action="javascript:void(0)">
<div class="v-login-item clearfix">
<label class="v-login-label">帐号:</label>
<input class="v-login-input" type="text" id="username" name="username" />
</div>
<div class="v-login-item clearfix">
<label class="v-login-label">密码:</label>
<input class="v-login-input" type="password" id="passw" name="passw" />
</div>
<div class="clearfix">
<label class="v-login-label"></label>
<div style="float:left;">
<input type="checkbox" class="v-login-checkbox" id="savelogin" name="savelogin" value="1"/>
<label>下次自动登录</label>
<a class="cblue" title="忘记密码" href="#">忘记密码?</a>
</div>
</div>
<div class="clearfix">
<label class="v-login-label"></label>
<input type="submit" value="登录" class="v-login-submit left" id="su"/>
<a href="#" title="注册" class="left v-login-reg" >注册</a>
<span class="info"></span>
</div>
</form>
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<include file="struts-default.xml">include</include>
<package name="user" namespace="/user" extends="json-default">
<action name="registerFormAction" class="action.user.RegisterFormAction">
<result name="register_form">/WEB-INF/jsp/user/register_form.jsp</result>
</action>
<!-- <action name="register" class="action.user.RegistAction">
<result name="success">/WEB-INF/jsp/main/index.jsp</result>
<result name="regist" type="dispatcher">/user/register_form.jsp</result>
</action>
-->
<action name="validEmail" class="action.user.ValidEmailAction">
<result name="success" type="json">
<param name="root">ok</param>
</result>
</action>
<action name="validCode" class="action.user.ValidImageCodeAction">
<result name="success" type="json">
<!-- 返回ok布尔值 -->
<param name="root">ok</param>
</result>
</action>
<action name="validName" class="action.user.ValidNameAction">
<result name="success" type="json">
<!-- 返回ok布尔值 -->
<param name="root">ok</param>
</result>
</action>
<action name="code" class="action.user.ImageCodeAction">
<result name="success" type="stream">
<param name="inputName">imageStream</param>
</result>
</action>
<action name="register" class="action.user.RegistAction">
<result name="success" type="redirectAction">../main.action</result>
<result name="regist" type="dispatcher">/WEB-INF/jsp/user/register_form.jsp</result>
</action>
<action name="logintest" class="action.user.LoginAction">
<result name="success" type="json">
<!-- 返回ok布尔值 -->
<param name="root">ok</param>
</result>
</action>
</package>
</struts>
public class LoginAction extends BaseAction{
private static final long serialVersionUID = 1L;
private String username;//="name";
private String passw;//="passw";
private boolean ok;
private String test;
public String getTest() {
return test;
}
public void setTest(String test) {
this.test = test;
}
public boolean isOk() {
return ok;
}
public void setOk(boolean ok) {
this.ok = ok;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassw() {
return passw;
}
public void setPassw(String passw) {
this.passw = passw;
}
public String execute(){
System.out.println("loginActionExecute()wocaonimei");
System.out.println("caonima");
try {
//System.out.println("caonima");
System.out.println(username);
System.out.println(passw);
System.out.println(test+"ni");
User user = userDAO.findByName(username);
String pwd = DegistUtil.produceDegistCode(passw);
if(user!=null && pwd.equals(user.getPassword())){
user.setAddIP(ObtainIP.obIP());
user.setLastLoginTime(new Timestamp(System.currentTimeMillis()));
userDAO.updateLogin(user);
session.put(Constant.LOGIN_KEY, user);
ok=true;
}else{
ok=false;
}
return "success";
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
ok=true;
return "error";
}
}
}