NutzCN Logo
问答 ajax添加user成功,但是控制台报错
发布于 2481天前 作者 小约翰 1852 次浏览 复制 上一个帖子 下一个帖子
标签:

在index.jsp中发送ajax请求
form表单代码

<div>
			<form action="#" id="loginForm2" method="post">
				<input name="id" type="hidden" id="id"> 用户名 <input
					name="name" type="text" value="admin"> 密码 <input
					name="password" type="password" value="123456">
				<button id="add_button">添加</button>
				<button id="update_button">修改</button>
			</form>
		</div>

js代码

$("#add_button").click(function() {
			$.ajax({
				url : base + "/user/add",
				type : "POST",
				data : $('#loginForm2').serialize(),
				dataType : "json",
				success : function(data) {
					console.log(data);
					if (!data.ok) {
						alert(data.msg);
					} else {
						alert(data.data.id);
					}
				}
			});
		});

提交之后

18-03-08 10:35:21.856 DEBUG [http-nio-8080-exec-18] INSERT INTO t_user(name,passwd,salt,ct,ut) VALUES(?,?,?,?,?) 
    |      1 |      2 |    3 |                   4 |                   5 |
    |--------|--------|------|---------------------|---------------------|
    | jason1 | 123456 | NULL | 2018-03-08 10:35:21 | 2018-03-08 10:35:21 |
  For example:> "INSERT INTO t_user(name,passwd,salt,ct,ut) VALUES('jason1','123456',NULL,'2018-03-08 10:35:21','2018-03-08 10:35:21') "
18-03-08 10:35:22.010 WARN [http-nio-8080-exec-18] Error@/user/add :
org.apache.catalina.connector.ClientAbortException: java.io.IOException: 您的主机中的软件中止了一个已建立的连接。
	at org.apache.catalina.connector.OutputBuffer.realWriteBytes(OutputBuffer.java:396)
	at org.apache.tomcat.util.buf.ByteChunk.flushBuffer(ByteChunk.java:426)
	at org.apache.catalina.connector.OutputBuffer.doFlush(OutputBuffer.java:345)
	at org.apache.catalina.connector.OutputBuffer.flush(OutputBuffer.java:320)
	at org.apache.catalina.connector.Response.flushBuffer(Response.java:496)
	at org.apache.catalina.connector.ResponseFacade.flushBuffer(ResponseFacade.java:318)
	at org.nutz.mvc.Mvcs.write(Mvcs.java:293)
	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:33)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.AdaptorProcessor.process(AdaptorProcessor.java:30)
	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.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:202)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:94)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:504)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
	at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:620)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:502)
	at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1132)
	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:684)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1539)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1495)
	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)
Caused by: java.io.IOException: 您的主机中的软件中止了一个已建立的连接。
	at sun.nio.ch.SocketDispatcher.write0(Native Method)
	at sun.nio.ch.SocketDispatcher.write(SocketDispatcher.java:51)
	at sun.nio.ch.IOUtil.writeFromNativeBuffer(IOUtil.java:93)
	at sun.nio.ch.IOUtil.write(IOUtil.java:65)
	at sun.nio.ch.SocketChannelImpl.write(SocketChannelImpl.java:471)
	at org.apache.tomcat.util.net.NioChannel.write(NioChannel.java:124)
	at org.apache.tomcat.util.net.NioBlockingSelector.write(NioBlockingSelector.java:101)
	at org.apache.tomcat.util.net.NioSelectorPool.write(NioSelectorPool.java:172)
	at org.apache.coyote.http11.InternalNioOutputBuffer.writeToSocket(InternalNioOutputBuffer.java:140)
	at org.apache.coyote.http11.InternalNioOutputBuffer.flushBuffer(InternalNioOutputBuffer.java:245)
	at org.apache.coyote.http11.InternalNioOutputBuffer.addToBB(InternalNioOutputBuffer.java:190)
	at org.apache.coyote.http11.InternalNioOutputBuffer.access$000(InternalNioOutputBuffer.java:42)
	at org.apache.coyote.http11.InternalNioOutputBuffer$SocketOutputBuffer.doWrite(InternalNioOutputBuffer.java:321)
	at org.apache.coyote.http11.filters.ChunkedOutputFilter.doWrite(ChunkedOutputFilter.java:116)
	at org.apache.coyote.http11.AbstractOutputBuffer.doWrite(AbstractOutputBuffer.java:256)
	at org.apache.coyote.Response.doWrite(Response.java:491)
	at org.apache.catalina.connector.OutputBuffer.realWriteBytes(OutputBuffer.java:391)
	... 42 more

5 回复

add()代码

@At
	public Object add(@Param("..") User user) {
		NutMap re = new NutMap();
		String msg = checkUser(user, true);
		if (msg != null) {
			return re.setv("ok", false).setv("msg", msg);
		}
		user.setCreateTime(new Date());
		user.setUpdateTime(new Date());
		user = dao.insert(user);
		return re.setv("ok", true).setv("data", user);
	}
			$.ajax({
				url : base + "/user/add",
				type : "POST",
				data : $('#loginForm2').serialize(),
				dataType : "json",
				success : function(data) {
					console.log(data);
					if (!data.ok) {
						alert(data.msg);
					} else {
						alert(data.data.id);
					}
				}
			});
                        return false;// 加一行

已解决,非常感谢

@wendal 请问,加上return false一行,代表什么意思呢

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