NutzCN Logo
问答 Ajax请求报IOException
发布于 2705天前 作者 qq_b079dbb7 1875 次浏览 复制 上一个帖子 下一个帖子
标签:

2017-07-26 09:47:33,595 org.nutz.mvc.impl.processor.FailProcessor.process(FailProcessor.java:28) WARN - Error@/user/loginDo :
org.apache.catalina.connector.ClientAbortException: java.io.IOException: 您的主机中的软件中止了一个已建立的连接。
at org.apache.catalina.connector.OutputBuffer.realWriteBytes(OutputBuffer.java:393)
at org.apache.tomcat.util.buf.ByteChunk.flushBuffer(ByteChunk.java:426)
at org.apache.catalina.connector.OutputBuffer.doFlush(OutputBuffer.java:342)
at org.apache.catalina.connector.OutputBuffer.flush(OutputBuffer.java:317)
at org.apache.catalina.connector.Response.flushBuffer(Response.java:510)
at org.apache.catalina.connector.ResponseFacade.flushBuffer(ResponseFacade.java:318)
at javax.servlet.ServletResponseWrapper.flushBuffer(ServletResponseWrapper.java:176)
at org.nutz.mvc.Mvcs.write(Mvcs.java:294)
at org.nutz.mvc.view.UTF8JsonView.render(UTF8JsonView.java:68)
at org.nutz.mvc.impl.processor.ViewProcessor.process(ViewProcessor.java:66)
at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
at org.nutz.mvc.impl.processor.MethodInvokeProcessor.process(MethodInvokeProcessor.java:28)
at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
at org.nutz.mvc.impl.processor.AdaptorProcessor.process(AdaptorProcessor.java:33)
at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
at org.nutz.mvc.impl.processor.ActionFiltersProcessor.process(ActionFiltersProcessor.java:58)
at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
at org.nutz.integration.shiro.NutShiroProcessor.process(NutShiroProcessor.java:126)
at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
at org.nutz.mvc.impl.processor.ModuleProcessor.process(ModuleProcessor.java:123)
at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
at org.nutz.mvc.impl.processor.EncodingProcessor.process(EncodingProcessor.java:27)
at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
at org.nutz.mvc.impl.processor.UpdateRequestAttributesProcessor.process(UpdateRequestAttributesProcessor.java:15)
at org.nutz.mvc.impl.NutActionChain.doChain(NutActionChain.java:44)
at org.nutz.mvc.impl.ActionInvoker.invoke(ActionInvoker.java:67)
at org.nutz.mvc.ActionHandler.handle(ActionHandler.java:31)
at org.nutz.mvc.NutFilter.doFilter(NutFilter.java:198)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.shiro.web.servlet.AbstractShiroFilter.executeChain(AbstractShiroFilter.java:449)
at org.apache.shiro.web.servlet.AbstractShiroFilter$1.call(AbstractShiroFilter.java:365)
at org.apache.shiro.subject.support.SubjectCallable.doCall(SubjectCallable.java:90)
at org.apache.shiro.subject.support.SubjectCallable.call(SubjectCallable.java:83)
at org.apache.shiro.subject.support.DelegatingSubject.execute(DelegatingSubject.java:383)
at org.apache.shiro.web.servlet.AbstractShiroFilter.doFilterInternal(AbstractShiroFilter.java:362)
at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:617)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1091)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:668)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1527)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1484)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)


``` @At("/user/loginDo") @Ok("json") @POST @Filters public Object login(@Param("..") NutMap map, @Attr(scope = Scope.SESSION,value = "_captcha") String _captcha){ String userName = map.getString("username"); System.out.println(userName); String pwd = map.getString("password"); String captcha = map.getString("captcha"); UserAccount userAccount = null; if (!ValidateUtils.isMobile(userName) || !ValidateUtils.isTruePwdType(pwd) || null == (userAccount = userService.findByPhone(userName, true))) return SpecificReturn.UserOrPasswdError; if (userAccount.isAccountDisable()) return SpecificReturn.UserAlreadyForbid; if (userAccount.getPasswordErrorTimes()> 2) { // 累计输错密码3次将进行验证码验证 if (!captcha.equalsIgnoreCase(_captcha)) return SpecificReturn.PicCodeWrong; }
16 回复

报错之前的日志也贴一下

比如return 图片验证码错误。ajax success:function(data){ if(data.Code==1011){//图片验证码错误
$('.login-error span').html(data.Message);
$('.login-error').css('display','block');
$('.login-content').css('padding-top','10px');
$(".login-content-validate").css("display","block");
$("#captcha_img").attr("src", base+"/captcha/next?w=132&h=34&" + new Date().getTime());//刷新验证码
$(".login-pwd").val("");
$(".validate").val("");
$(".validate").focus();
return false;
}
...
return false后,页面自动刷新,且地址栏带form表单参数。如何解决这里的return后还刷新页面,大神们。

报错前的日志:
2017-07-26 09:58:39,161 org.apache.shiro.web.servlet.SimpleCookie.readValue(SimpleCookie.java:366) DEBUG - Found 'session_id' cookie value [86307153-6e71-4d25-8d6b-c38620cf83ce]
2017-07-26 09:58:39,176 net.sf.ehcache.store.disk.Segment.put(Segment.java:434) DEBUG - put added 0 on heap
2017-07-26 09:58:39,176 net.sf.ehcache.store.disk.Segment.put(Segment.java:462) DEBUG - put updated, deleted 0 on heap
2017-07-26 09:58:39,176 net.sf.ehcache.store.disk.Segment.put(Segment.java:466) DEBUG - put updated, deleted 0 on disk
2017-07-26 09:58:39,176 org.nutz.mvc.impl.UrlMappingImpl.get(UrlMappingImpl.java:101) DEBUG - Found mapping for [POST] path=/user/checkUserLogin : LoginAction.checkUserLogin(LoginAction.java:126)
2017-07-26 09:58:39,176 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:151) DEBUG - Get 'loginAction'<class com.feibei.water_financial_live.modules.action.web.LoginAction>
2017-07-26 09:58:39,176 net.sf.ehcache.store.disk.Segment.faultInternal(Segment.java:764) DEBUG - fault removed 0 from heap
2017-07-26 09:58:39,176 net.sf.ehcache.store.disk.Segment.faultInternal(Segment.java:776) DEBUG - fault added 0 on disk
2017-07-26 09:58:39,176 org.nutz.dao.impl.sql.run.NutDaoExecutor.printSQL(NutDaoExecutor.java:388) DEBUG - SELECT * FROM user_account WHERE username=? LIMIT 0, 1
| 1 |
|-------------|
| 13728908380 |
For example:> "SELECT * FROM user_account WHERE username='13728908380' LIMIT 0, 1 "
2017-07-26 09:58:39,203 org.apache.shiro.web.servlet.SimpleCookie.readValue(SimpleCookie.java:366) DEBUG - Found 'session_id' cookie value [86307153-6e71-4d25-8d6b-c38620cf83ce]
2017-07-26 09:58:39,204 net.sf.ehcache.store.disk.Segment.put(Segment.java:434) DEBUG - put added 0 on heap
2017-07-26 09:58:39,205 net.sf.ehcache.store.disk.Segment.put(Segment.java:462) DEBUG - put updated, deleted 0 on heap
2017-07-26 09:58:39,205 net.sf.ehcache.store.disk.Segment.put(Segment.java:466) DEBUG - put updated, deleted 0 on disk
2017-07-26 09:58:39,205 org.nutz.mvc.impl.UrlMappingImpl.get(UrlMappingImpl.java:101) DEBUG - Found mapping for [GET] path=/captcha/next : CaptchaModule.next(CaptchaModule.java:27)
2017-07-26 09:58:39,205 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:151) DEBUG - Get 'captchaModule'<class com.feibei.water_financial_live.modules.controllers.CaptchaModule>
2017-07-26 09:58:39,206 net.sf.ehcache.store.disk.Segment.faultInternal(Segment.java:764) DEBUG - fault removed 0 from heap
2017-07-26 09:58:39,208 net.sf.ehcache.store.disk.Segment.faultInternal(Segment.java:776) DEBUG - fault added 0 on disk
*****************验证码:dvq1
2017-07-26 09:58:39,212 net.sf.ehcache.store.disk.Segment.put(Segment.java:434) DEBUG - put added 0 on heap
2017-07-26 09:58:39,213 net.sf.ehcache.store.disk.Segment.put(Segment.java:462) DEBUG - put updated, deleted 0 on heap
2017-07-26 09:58:39,213 net.sf.ehcache.store.disk.Segment.put(Segment.java:466) DEBUG - put updated, deleted 0 on disk
2017-07-26 09:58:39,213 net.sf.ehcache.store.disk.Segment.faultInternal(Segment.java:764) DEBUG - fault removed 0 from heap
2017-07-26 09:58:39,213 net.sf.ehcache.store.disk.Segment.faultInternal(Segment.java:776) DEBUG - fault added 0 on disk

回复按钮旁边就是"插入代码或日志片段"的按钮!!!

$.ajax({
			type : "post",
			url : base+'/user/loginDo',
			data : {
				"username":phone,
				"password":password,
				"captcha":captcha
			},
			dataType : "json",
			success : function(data){console.log(data);return;
				if(data.Code==200){//登陆成功
					$('.login-Other').css({'margin-bottom':'24px','margin-top':'30px'});
					//window.location.reload();
					parent.location.reload();
				}else if(data.Code==1001){//手机号码不正确
					$('.login-error span').html(data.Message);
					$('.login-error').css('display','block');
					$('.login-content').css('padding-top','10px');
					$('.login-btn').css('margin-top','10px');
					$('.login-content p').css({'margin-bottom':'18px','margin-top':'20px'});
					$('.login-Other').css({'margin-bottom':'16px','margin-top':'20px'});
					$(".login-pwd").val("");
					$(".login-phone").focus();
					return false;
				}else if(data.Code==1005){//用户名或密码错误
					$('.login-error span').html(data.Message);
					$('.login-error').css('display','block');
					$('.login-content').css('padding-top','10px');
					$('.login-btn').css('margin-top','10px');
					$(".login-pwd").val("");
					//$(".login-phone").focus();
					if($('.login-content-validate').css('display')!="none"){
						$("#captcha_img").attr("src", base+"/captcha/next?w=132&h=34&" + new Date().getTime());
					}else{
						checkLogin();
					}
					$(".validate").val("");
					$(".validate").focus();
					return false;
				}else if(data.Code==1011){//图片验证码错误
					$('.login-error span').html(data.Message);
					$('.login-error').css('display','block');
					$('.login-content').css('padding-top','10px');
					$(".login-content-validate").css("display","block");
					$("#captcha_img").attr("src", base+"/captcha/next?w=132&h=34&" + new Date().getTime());//刷新验证码
					$(".login-pwd").val("");
					$(".validate").val("");
					$(".validate").focus();
					return false;
				}else if(data.Code==1014){//展示图片验证码
					$('.login-error span').html(data.Message);
					$('.login-error').css('display','block');
					$('.login-content').css('padding-top','10px');
					$(".login-content-validate").css("display","block");
					//$("#captcha_img").attr("src", base+"/captcha/next?w=132&h=34&" + new Date().getTime());//刷新验证码
					$(".validate").val("");
					$(".login-pwd").val("");
					$(".validate").focus();
					return false;
				}else{
					$('.login-error span').html(data.Message);
					$('.login-error').css('display','block');
					$('.login-Other').css({'margin-bottom':'24px','margin-top':'30px'});
					$('.login-content').css('padding-top','10px');
					if($('.login-content-validate').css('display')!="none"){
						$("#captcha_img").attr("src", base+"/captcha/next?w=132&h=34&" + new Date().getTime());
					}
					$(".login-pwd").val("");
					return false;
				}
			}
       });

贴js代码,完整一点

$('.login-btn').click(function(){
		
		var phone = $(".login-phone").val();
		var password= $(".login-pwd").val();
		var captcha=$(".validate").val();
		if(!checkPhone(phone)){
			$('.login-error span').html("手机号码错误,请重新输入!");
			$('.login-error').css('display','block');
			$('.login-content').css('padding-top','10px');
			$('.login-Other').css({'margin-bottom':'24px','margin-top':'30px'});
			return false;
		}
		if($('.login-content-validate').css('display')!="none"){
			if(captcha==""){
				$('.login-error span').html("请输入验证码!");
				$('.login-error').css('display','block');
				return false;
			}
		}
		if(!checkPassword(password)){
			$('.login-error span').html("请输入格式正确的密码(6-15位)");
			$('.login-error').css('display','block');
			$('.login-content').css('padding-top','1px');
			$('.login-Other').css({'margin-bottom':'24px','margin-top':'30px'});
			return false;
		}
		/**
		 * 记住用户名
		 */
		/*if($("#remember_phone")[0].checked){
	        $.cookie("userName",phone,{expires:7});  //保存七天  
		}*/
		$('.login-error').css('display','none');
		$.ajax({
			type : "post",
			url : base+'/user/loginDo',
			data : {
				"username":phone,
				"password":password,
				"captcha":captcha
			},
			dataType : "json",
			success : function(data){console.log(data);return;
				if(data.Code==200){//登陆成功
					$('.login-Other').css({'margin-bottom':'24px','margin-top':'30px'});
					//window.location.reload();
					parent.location.reload();
				}else if(data.Code==1001){//手机号码不正确
					$('.login-error span').html(data.Message);
					$('.login-error').css('display','block');
					$('.login-content').css('padding-top','10px');
					$('.login-btn').css('margin-top','10px');
					$('.login-content p').css({'margin-bottom':'18px','margin-top':'20px'});
					$('.login-Other').css({'margin-bottom':'16px','margin-top':'20px'});
					$(".login-pwd").val("");
					$(".login-phone").focus();
					return false;
				}else if(data.Code==1005){//用户名或密码错误
					$('.login-error span').html(data.Message);
					$('.login-error').css('display','block');
					$('.login-content').css('padding-top','10px');
					$('.login-btn').css('margin-top','10px');
					$(".login-pwd").val("");
					//$(".login-phone").focus();
					if($('.login-content-validate').css('display')!="none"){
						$("#captcha_img").attr("src", base+"/captcha/next?w=132&h=34&" + new Date().getTime());
					}else{
						checkLogin();
					}
					$(".validate").val("");
					$(".validate").focus();
					return false;
				}else if(data.Code==1011){//图片验证码错误
					$('.login-error span').html(data.Message);
					$('.login-error').css('display','block');
					$('.login-content').css('padding-top','10px');
					$(".login-content-validate").css("display","block");
					$("#captcha_img").attr("src", base+"/captcha/next?w=132&h=34&" + new Date().getTime());//刷新验证码
					$(".login-pwd").val("");
					$(".validate").val("");
					$(".validate").focus();
					return false;
				}else if(data.Code==1014){//展示图片验证码
					$('.login-error span').html(data.Message);
					$('.login-error').css('display','block');
					$('.login-content').css('padding-top','10px');
					$(".login-content-validate").css("display","block");
					//$("#captcha_img").attr("src", base+"/captcha/next?w=132&h=34&" + new Date().getTime());//刷新验证码
					$(".validate").val("");
					$(".login-pwd").val("");
					$(".validate").focus();
					return false;
				}else{
					$('.login-error span').html(data.Message);
					$('.login-error').css('display','block');
					$('.login-Other').css({'margin-bottom':'24px','margin-top':'30px'});
					$('.login-content').css('padding-top','10px');
					if($('.login-content-validate').css('display')!="none"){
						$("#captcha_img").attr("src", base+"/captcha/next?w=132&h=34&" + new Date().getTime());
					}
					$(".login-pwd").val("");
					return false;
				}
			}
       });
       
		
       
	});

@wendal 后台代码

/**
	 * 登陆
	 * 
	 * @param map
	 * @param _captcha
	 * @return
	 */
	@At("/user/loginDo")
	@POST
	@Filters
	public Object login(@Param("..") NutMap map, @Attr(scope = Scope.SESSION,value = "_captcha") String _captcha){
		String userName = map.getString("username");
		System.out.println(userName);
		String pwd = map.getString("password");
		String captcha = map.getString("captcha");
		UserAccount userAccount = null;
		if (!ValidateUtils.isMobile(userName) || !ValidateUtils.isTruePwdType(pwd) || null == (userAccount = userService.findByPhone(userName, true)))
			return SpecificReturn.UserOrPasswdError;
		if (userAccount.isAccountDisable())
			return SpecificReturn.UserAlreadyForbid;
		if (userAccount.getPasswordErrorTimes()> 2) { // 累计输错密码3次将进行验证码验证
			if (!captcha.equalsIgnoreCase(_captcha))
				return SpecificReturn.PicCodeWrong;
		}
		if(!userService.checkPwd(userAccount, pwd)){
			userService.refreshUserAccount(userAccount,false);
			//return SpecificReturn.PwdWrong;
			return SpecificReturn.UserOrPasswdError;
		}else{
			userService.refreshUserAccount(userAccount,true);
		}
		if(userAccount.isAccountDisable()){
			return SpecificReturn.AccountDisabled;
		}
		//Toolkit.doLogin(new SimpleShiroToken(userAccount), userAccount.getUserId());
		System.out.println("************************"+Mvcs.getServletContext().getAttribute("AvatorSmall").toString());
		UserInfo userInfo=userAccount.getUserInfo();
		if(Strings.isBlank(userInfo.getAvatar())){
			userInfo.setAvatar(Mvcs.getServletContext().getAttribute("AvatorSmall").toString());
		}
		Toolkit.doLogin(new SimpleShiroToken(userInfo), userAccount.getUserId());
		System.out.println("********************"+Toolkit.uid());
		return SpecificReturn.Success;
    }

@wendal 用postman测试能返回结果,比如:{"Code":1011,"Message":"图片验证码错误"}

$.ajax({

});
// 后面加
return false;

@wendal 谢谢,解决了。请问造成这样的原因是什么啊?

写在外面才能终止event

意思是ajax里的return并不能终止click的这个事件?

添加回复
请先登陆
回到顶部