谁能给个最最最最最最最最最最最最最最最最最最最最最最最最最最简单的Struts2+AJAX+JSP的验证实例吗?
最主要的是AJAX请求到Action时候的URL怎么写,action又要怎么配置。就七十分!全给一个人吧
最主要的是AJAX请求到Action时候的URL怎么写,action又要怎么配置。就七十分!全给一个人吧
解决方案 »
- iframe布局
- 我做web开发,提供一个excel下载的功能。点导出后就弹出个框,让选打开还是保存。现在保存的话没有问题。一点打开,就提示说在Temporary Internet Files文件夹下没有我要打开的文件
- struts-layout
- 关于树的问题
- 数据库中的集合函数(max,min等)是不是不能操作中间结果
- 访问webservice出错
- javaWeb ajax轮询 服务器推送
- struts国际化的问题
- Tomcat中关于Servlet或数据库或Bean中出现的中文原因
- 关于动态创建数据和数据表,求高手指导!在此谢过
- oracle问题
- The server does not support version 3.0 of the J2EE Web module specification
package com.softeem.mail.action;import java.io.ByteArrayInputStream;
import java.io.InputStream;import javax.servlet.http.Cookie;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.softeem.mail.entity.Users;
import com.softeem.mail.factory.Factory;
import com.softeem.mail.service.UsersService;public class UserLoginAction extends ActionSupport{
private static final long serialVersionUID = 1L;
private String name;
private String password;
private String remerber_password; public InputStream getLogin() {
UsersService usersService = Factory.getUsersService();
Users users = usersService.checkLogin(name, password);
ByteArrayInputStream input = null;
if(users.getId() != 0){
ActionContext.getContext().getSession().put("users", users);
if("on".equals(remerber_password)){
Cookie cookieuser = new Cookie("user",name+"-"+password);
cookieuser.setMaxAge(60*60*24*7);
}
input = new ByteArrayInputStream("ok".getBytes());
return input;
}else{
input = new ByteArrayInputStream("error".getBytes());
return input;
}
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getRemerber_password() {
return remerber_password;
}
public void setRemerber_password(String remerberPassword) {
remerber_password = remerberPassword;
}
}Action的XML配置
<action name="userLoginAction" class="com.softeem.mail.action.UserLoginAction">
<result type="stream">
<param name="contentType">text</param>
<param name="inputName">login</param>
</result>
</action>JSP页面代码
<script type="text/javascript">
/*提交验证,异步传输*/
$(document).ready(function(){
$("form").submit(function (){
if ($("#name").val() == '' || $("#password").val() == ''){
alert("帐号和密码不能为空!");
return false;
}else{
$.ajax({
url: 'userLoginAction', //处理测试页面,注意返回内容,成功返回OK
dataType: 'text',
data: $("form").serialize(),
success: function (msg) {
if (msg == "ok"){
window.location.href = "fail.jsp";
}else{
alert(msg);
alert("帐号或密码不正确,请您重新输入!");
return;
}
}
});
}
return false; ////////////////要阻止表单提交
});
});