NutzCN Logo
精华 关于nutz 文件上传进度条的问题 请求指教
发布于 3140天前 作者 qq_7db27eef 2478 次浏览 复制 上一个帖子 下一个帖子
标签:

关于文件上传 进度条的显示 !我的思路是提交表单后,每20毫秒 取一次 上传进度 !代码如下!
sum 文件大小正常
current 一直为零
*

求解!!!

前台 在提交表单后:

 setInterval (getP, 20);

function getP(){
		  
		$.ajax({
	        url      : "${ctx}/admin/getproess",
	        type     : "POST",
	        data     : $(this).serialize(),
	        cache    : false, 
	        async    : true,
	        dataType : "json",
	        success  : function(obj) {
	        	if(obj != null){
	        		alert("aaa"+obj.ss);
	        		if(obj._type == "ok"){
	        			$.zxxbox.hide();
	        			Q.go(Q.lash+"_A1_d_A2_"+Date.parse(new Date()));
	        		}
	        	}
	        }
	});
	  
	}
	
@At
    public NutMap getproess(HttpServletRequest req) {
		 UploadInfo SS=Uploads.getInfo(req);
		Long ss= SS.sum ;
		Long cc= SS.current ;
		
		String size=ss.toString();
		String current=cc.toString();
		 System.out.print("文件大小"+size+"当前上传"+current );
		 
		 NutMap m =new NutMap();
		 m.setv("ss",SS.current );
        return m;
    }
34 回复

建议用webupload/jq fileuplpad等js库,这些js库均有进度相关的api

getproess 这方法应该每秒都访问一下才行哦

@wendal 已经够快了 20ms 访问一次 sum 取到的 是正确的 !! current 一直是零!!! 是个bug吗??

没有限制文件大小吧? debug一下FastUploading的181行,里面有info.current的赋值

@qq_7db27eef 那就是限制大小了,走167行了

@wendal debug 是有值得 取出来就是零了!

@qq_7db27eef
那看来不是同一个对象

@wendal 刚才说的不准确 是debug 的时候 能打印出来值 !正常跑 出来就是零了

@wendal 大哥!我是小新手 刚接触这个,还望您多多指教啊!

@qq_7db27eef
上传文件的代码贴一下

@AdaptBy(type=UploadAdaptor.class, args={"${app.root}/WEB-INF/tmp/user_avatar", "8192", "utf-8", "20000", ""})
    @POST
    @Ok("json")
    @At("/avatar")
    public NutMap uploadAvatar(@Param("file")TempFile tf,
    		@Param("x1")String  x,
    		@Param("y1")String  y,
    		@Param("w")String  w,
    		@Param("h")String  h,
            @Attr(scope=Scope.SESSION, value="sessionUser")Users id,
            HttpSession session,
            AdaptorErrorContext err,HttpServletResponse response,HttpServletRequest req) {
		NutMap m =new NutMap();
		System.out.print("userIduserIduserIduserIduserIduserIduserIduserIduserIduserIduserIduserIduserIduserIduserId"+id.getId());    
		Users profile = Daos.ext(dao, FieldFilter.locked(Users.class, "avatar")).fetch(Users.class, id.getId());
		
		String picurl=id.getPic();
		  String a = jiequ(picurl);   
		Date now = new Date(); 
		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");//可以方便地修改日期格式
		String	HAOMIAO=	String.valueOf(System.currentTimeMillis()) ;
	String  newurl=id.getId()+HAOMIAO;
  
		String hehe = dateFormat.format( now ); 
		System.out.println("HAOMIAO"+HAOMIAO); 
        String msg = null;
        if (err != null && err.getAdaptorErr() != null) {
            msg = "文件大小不符合规定";
        } else if (tf == null) {
            msg = "空文件";
        } else {
        	
        	msg="成功";

            try {
                @SuppressWarnings("deprecation")
				BufferedImage image = Images.read(tf.getInputStream());
              
                ByteArrayOutputStream out = new ByteArrayOutputStream();
                Images.writeJpeg(image, out, 0.8f);
                System.out.print("存入");
                System.out.println("dada."+a);
              ImageIO.write(image, "jpg", new File("e:/" +"temp/"+ a));
              
              String ss="e:/temp/";
             imgCut("e:/" +"temp/"+ a,11,11,80,80);

            } catch(DaoException e) {
               
                msg = "系统错误";
            } catch (Throwable e) {
            	System.out.print("cuowu图片格式错误图片格式错误图片格式错误图片格式错误图片格式错误图片格式错误"+e);
                msg = "图片格式错误";
            }
        }

        if (msg != null)
            Mvcs.getHttpSession().setAttribute("upload-error-msg", msg);
        File f=new File("e:/temp/"+a);   
 
      File mm=new File("e:/temp/"+newurl+".png");   
       if(f.renameTo(mm))   
        {   
        System.out.println("修改成功!");   
        }   
        else   
       {   
       System.out.println("修改失败");   
       }  
        profile.setPic( "/static_img/"+newurl+".png");
        Daos.ext(dao, FieldFilter.create(Users.class, null, "avatar", true)).update(profile);
     m.setv("msg", msg);
     m.setv("url", "/static_img/"+newurl+".png");
        return m;
    }
	
	public String jiequ(String url){
		int index = url.lastIndexOf("/");  
		  //将字符串转为字符数组  
		  char[] ch = url.toCharArray();  
		  //根据 copyValueOf(char[] data, int offset, int count) 取得最后一个字符串  
		  String lastString = String.copyValueOf(ch, index + 1, ch.length - index - 1); 
		  return lastString;
	}
	 public void renameFile(String file, String toFile) {

	        File toBeRenamed = new File(file);
	        //检查要重命名的文件是否存在,是否是文件
	        if (!toBeRenamed.exists() || toBeRenamed.isDirectory()) {

	            System.out.println("File does not exist: " + file);
	            return;
	        }

	        File newFile = new File(toFile);

	        //修改文件名
	        if (toBeRenamed.renameTo(newFile)) {
	            System.out.println("File has been renamed.");
	        } else {
	            System.out.println("Error renmaing file");
	        }

	    }
	 public static void imgCut(String srcImageFile, int x, int y, int desWidth,
             int desHeight) {
try {
Image img;
ImageFilter cropFilter;
BufferedImage bi = ImageIO.read(new File(srcImageFile));
int srcWidth = bi.getWidth();
int srcHeight = bi.getHeight();
if (srcWidth >= desWidth && srcHeight >= desHeight) {
Image image = bi.getScaledInstance(srcWidth, srcHeight,Image.SCALE_DEFAULT);
cropFilter = new CropImageFilter(x, y, desWidth, desHeight);
img = Toolkit.getDefaultToolkit().createImage(
       new FilteredImageSource(image.getSource(), cropFilter));
BufferedImage tag = new BufferedImage(desWidth, desHeight,
       BufferedImage.TYPE_INT_RGB);
Graphics g = tag.getGraphics();
g.drawImage(img, 0, 0, null);
g.dispose();
//输出文件
ImageIO.write(tag, "JPEG", new File(srcImageFile+"333.jpg"));
}
} catch (Exception e) {
e.printStackTrace();
}
}

js那头的代码


$("body").delegate("form.ajaxUpload1","submit",function(){ var formData = new FormData($(this)[0]); $.ajax({ url : $(this).attr("action"), type : "POST", data : formData, cache : false, async : true, contentType: false, //这两句需要添加上,否则会跳转页面 processData: false, dataType : "json", success : function(obj) { if(obj != null){ alert(obj.ss); if(obj._type == "ok"){ //$.zxxbox.hide(); //Q.go(Q.lash+"_A1_d_A2_"+Date.parse(new Date())); } } } }); setInterval (getP, 2000); return false; }); function getP(){ $.ajax({ url : "${ctx}/admin/getproess", type : "POST", data : $(this).serialize(), cache : false, async : true, dataType : "json", success : function(obj) { if(obj != null){ alert("aaa"+obj.ss); } } }); }

我写了段代码测试了一下

页面端:

<form action="${base}/demo/upload" method="post" enctype="multipart/form-data">
	<input name="file" type="file">
	<input type="submit">
</form>
<script type="text/javascript">
function getP() {
	$.ajax({
		url : "${base}/demo/uploadp",
		success : function (d) {
			if (d)
				console.log(d);
		},
		//async:false
	});
}
setInterval (getP, 50);
</script>

入口方法端

package net.wendal.nutzbook.module;

import java.io.IOException;
import java.util.Date;

import javax.servlet.http.HttpServletRequest;

import org.nutz.json.Json;
import org.nutz.mvc.annotation.AdaptBy;
import org.nutz.mvc.annotation.At;
import org.nutz.mvc.annotation.Ok;
import org.nutz.mvc.annotation.Param;
import org.nutz.mvc.upload.TempFile;
import org.nutz.mvc.upload.UploadAdaptor;
import org.nutz.mvc.upload.Uploads;

@At("/demo")
public class DemoModule {
    
    @At
    @AdaptBy(type=UploadAdaptor.class)
    public void upload(@Param("file")TempFile tmp) throws IOException{
        if (tmp != null)
            tmp.delete();
    }
    
    @At
    @Ok("json")
    public Object uploadp(HttpServletRequest req) {
        return Uploads.getInfo(req);
    }
}

Chrome输出(选择Preserve Log,防止跳转后日志丢失):

Object {sum: 35906246, current: 1499136, stop: false} param_list.jsp:48 
Object {sum: 35906246, current: 3514368, stop: false} param_list.jsp:48 
Object {sum: 35906246, current: 5742592, stop: false} param_list.jsp:48 
Object {sum: 35906246, current: 8077312, stop: false} param_list.jsp:48 
Object {sum: 35906246, current: 10510336, stop: false} param_list.jsp:48 
Object {sum: 35906246, current: 13041664, stop: false} param_list.jsp:48 
Object {sum: 35906246, current: 15253504, stop: false} param_list.jsp:48 
Object {sum: 35906246, current: 18341888, stop: false} param_list.jsp:48 
Object {sum: 35906246, current: 20086784, stop: false} param_list.jsp:48 
Object {sum: 35906246, current: 23109632, stop: false} param_list.jsp:48 
Object {sum: 35906246, current: 23478272, stop: false} param_list.jsp:48 
Object {sum: 35906246, current: 24559616, stop: false} param_list.jsp:48 
Object {sum: 35906246, current: 26943488, stop: false} param_list.jsp:48 
Object {sum: 35906246, current: 27557888, stop: false} param_list.jsp:48 
Object {sum: 35906246, current: 30433280, stop: false} param_list.jsp:48 
Object {sum: 35906246, current: 33325056, stop: false} param_list.jsp:48 
Object {sum: 35906246, current: 0, stop: false}

但也发现个问题,就是 最后一次的时候 current变成0了原因我需要查查

@qq7db27eef 找到问题了,告诉我啊 谢谢了

@qq_7db27eef 找到问题了,告诉我啊 谢谢了

@wendal 找到问题了吗?

@qq_7db27eef
看那个issue,已经提交修改了

@wendal 哦哦 那改好的在那里下载!

@wendal 这是改好的吗?下载就可以用了吧

@wendal 那个zip 怎么用啊 怎么 打成jar

有快照版的链接地址,直接下载jar,如果是maven的话就引用快照版。

下载最后面(也就是最新日期的那个)

包有问题跑不起来

log4j: 2016-05-18 16:38:47,894 [localhost-startStop-1] INFO  org.nutz.mvc.impl.NutLoading - Build URL mapping by org.nutz.mvc.impl.UrlMappingImpl ...
log4j: 2016-05-18 16:38:47,895 [localhost-startStop-1] DEBUG org.nutz.mvc.impl.NutLoading - @Views(BeetlViewMaker.class,DefaultViewMaker.class)
log4j: 2016-05-18 16:38:47,898 [localhost-startStop-1] ERROR org.nutz.mvc.impl.NutLoading - Error happend during start serivce!
java.lang.NullPointerException
	at java.io.Reader.<init>(Unknown Source)
	at java.io.InputStreamReader.<init>(Unknown Source)
	at org.nutz.mvc.impl.chainconfig.JsonActionChainMakerConfiguretion.<init>(JsonActionChainMakerConfiguretion.java:31)
	at org.nutz.mvc.impl.NutActionChainMaker.<init>(NutActionChainMaker.java:28)
	at org.nutz.mvc.impl.NutLoading.createChainMaker(NutLoading.java:262)
	at org.nutz.mvc.impl.NutLoading.evalUrlMapping(NutLoading.java:168)
	at org.nutz.mvc.impl.NutLoading.load(NutLoading.java:107)
	at org.nutz.mvc.ActionHandler.<init>(ActionHandler.java:19)
	at org.nutz.mvc.NutFilter._init(NutFilter.java:87)
	at org.nutz.mvc.NutFilter.init(NutFilter.java:65)
	at org.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java:279)
	at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:260)
	at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:105)
	at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4855)
	at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5549)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1574)
	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1564)
	at java.util.concurrent.FutureTask.run(Unknown Source)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	at java.lang.Thread.run(Unknown Source)
log4j: 2016-05-18 16:38:47,900 [localhost-startStop-1] ERROR org.nutz.mvc.impl.NutLoading - try to depose ioc
log4j: 2016-05-18 16:38:47,902 [localhost-startStop-1] INFO  org.nutz.ioc.impl.NutIoc - org.nutz.ioc.impl.NutIoc@1815855162 is closing. startup date [16-05-18 16:38:47.890]
log4j: 2016-05-18 16:38:47,902 [localhost-startStop-1] INFO  org.nutz.ioc.impl.NutIoc - org.nutz.ioc.impl.NutIoc@1815855162 is deposed. startup date [16-05-18 16:38:47.890]
五月 18, 2016 4:38:47 下午 org.apache.catalina.core.StandardContext filterStart
严重: Exception starting filter nutz
org.nutz.mvc.LoadingException: java.lang.NullPointerException
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
	at java.lang.reflect.Constructor.newInstance(Unknown Source)
	at org.nutz.lang.born.ConstructorBorning.born(ConstructorBorning.java:17)
	at org.nutz.lang.born.BornContext.doBorn(BornContext.java:60)
	at org.nutz.lang.Mirror.born(Mirror.java:990)
	at org.nutz.lang.Lang.wrapThrow(Lang.java:169)
	at org.nutz.mvc.impl.NutLoading.load(NutLoading.java:134)
	at org.nutz.mvc.ActionHandler.<init>(ActionHandler.java:19)
	at org.nutz.mvc.NutFilter._init(NutFilter.java:87)
	at org.nutz.mvc.NutFilter.init(NutFilter.java:65)
	at org.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java:279)
	at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:260)
	at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:105)
	at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4855)
	at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5549)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1574)
	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1564)
	at java.util.concurrent.FutureTask.run(Unknown Source)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NullPointerException
	at java.io.Reader.<init>(Unknown Source)
	at java.io.InputStreamReader.<init>(Unknown Source)
	at org.nutz.mvc.impl.chainconfig.JsonActionChainMakerConfiguretion.<init>(JsonActionChainMakerConfiguretion.java:31)
	at org.nutz.mvc.impl.NutActionChainMaker.<init>(NutActionChainMaker.java:28)
	at org.nutz.mvc.impl.NutLoading.createChainMaker(NutLoading.java:262)
	at org.nutz.mvc.impl.NutLoading.evalUrlMapping(NutLoading.java:168)
	at org.nutz.mvc.impl.NutLoading.load(NutLoading.java:107)
	... 15 more

五月 18, 2016 4:38:47 下午 org.apache.catalina.core.StandardContext startInternal
严重: One or more Filters failed to start. Full details will be found in the appropriate container log file
五月 18, 2016 4:38:47 下午 org.apache.catalina.core.StandardContext startInternal
严重: Context [/jxzgweb0329] startup failed due to previous errors
五月 18, 2016 4:38:47 下午 org.apache.coyote.AbstractProtocol start
信息: Starting ProtocolHandler ["http-bio-8080"]
五月 18, 2016 4:38:47 下午 org.apache.coyote.AbstractProtocol start
信息: Starting ProtocolHandler ["ajp-bio-8009"]
五月 18, 2016 4:38:47 下午 org.apache.catalina.startup.Catalina start
信息: Server startup in 1893 ms

上边那个 好了 查询登陆 报这个错误

  | 2016-05-18 16:43:37 | 10000 |
  For example:> "UPDATE users SET logTime='2016-05-18 16:43:37'  WHERE id=10000"
log4j: 2016-05-18 16:43:37,509 [http-bio-8080-exec-10] DEBUG org.nutz.dao.impl.sql.run.NutDaoExecutor - INSERT INTO logs(uID,ip,addTime,jj,xq,`sql`) VALUES(?,?,?,?,?,?) 
    |     1 |         2 |                   3 |  4 |                                         5 | 6 |
    |-------|-----------|---------------------|----|-------------------------------------------|--|
    | 10000 | 127.0.0.1 | 2016-05-18 16:43:37 | 登录 | 用户[sysAdmin]在[2016-05-18 16:43:37]登录系统成功。 |  |
  For example:> "INSERT INTO logs(uID,ip,addTime,jj,xq,`sql`) VALUES(10000,'127.0.0.1','2016-05-18 16:43:37','登录','用户[sysAdmin]在[2016-05-18 16:43:37]登录系统成功。','') "
log4j: 2016-05-18 16:43:37,513 [http-bio-8080-exec-10] DEBUG org.nutz.dao.impl.sql.run.NutDaoExecutor - SQLException
java.sql.SQLException: '`' 附近有语法错误。
	at net.sourceforge.jtds.jdbc.SQLDiagnostic.addDiagnostic(SQLDiagnostic.java:368)
	at net.sourceforge.jtds.jdbc.TdsCore.tdsErrorToken(TdsCore.java:2816)
	at net.sourceforge.jtds.jdbc.TdsCore.nextToken(TdsCore.java:2254)
	at net.sourceforge.jtds.jdbc.TdsCore.getMoreResults(TdsCore.java:631)
	at net.sourceforge.jtds.jdbc.JtdsStatement.processResults(JtdsStatement.java:584)
	at net.sourceforge.jtds.jdbc.JtdsStatement.executeSQL(JtdsStatement.java:546)
	at net.sourceforge.jtds.jdbc.JtdsPreparedStatement.execute(JtdsPreparedStatement.java:559)
	at org.nutz.dao.impl.sql.run.NutDaoExecutor._runPreparedStatement(NutDaoExecutor.java:268)
	at org.nutz.dao.impl.sql.run.NutDaoExecutor.exec(NutDaoExecutor.java:82)
	at org.nutz.dao.impl.DaoSupport$DaoExec.invoke(DaoSupport.java:327)
	at org.nutz.dao.impl.sql.run.NutDaoRunner.run(NutDaoRunner.java:59)
	at org.nutz.dao.impl.DaoSupport.run(DaoSupport.java:250)
	at org.nutz.dao.impl.DaoSupport._exec(DaoSupport.java:282)
	at org.nutz.dao.impl.EntityOperator.exec(EntityOperator.java:50)
	at org.nutz.dao.impl.NutDao.insert(NutDao.java:158)
	at com.jxzg.web.IndexAction.checkLogin(IndexAction.java:103)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at org.nutz.mvc.impl.processor.MethodInvokeProcessor.process(MethodInvokeProcessor.java:25)
	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.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:241)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
	at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:957)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:423)
	at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1079)
	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:620)
	at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:318)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.lang.Thread.run(Unknown Source)
log4j: 2016-05-18 16:43:37,515 [http-bio-8080-exec-10] WARN  org.nutz.mvc.impl.processor.FailProcessor - Error@/checkLogin :
org.nutz.dao.DaoException: !Nutz SQL Error: 'INSERT INTO logs(uID,ip,addTime,jj,xq,`sql`) VALUES(?,?,?,?,?,?) 
    |     1 |         2 |                   3 |  4 |                                         5 | 6 |
    |-------|-----------|---------------------|----|-------------------------------------------|--|
    | 10000 | 127.0.0.1 | 2016-05-18 16:43:37 | 登录 | 用户[sysAdmin]在[2016-05-18 16:43:37]登录系统成功。 |  |
  For example:> "INSERT INTO logs(uID,ip,addTime,jj,xq,`sql`) VALUES(10000,'127.0.0.1','2016-05-18 16:43:37','登录','用户[sysAdmin]在[2016-05-18 16:43:37]登录系统成功。','') "'
PreparedStatement: 
'INSERT INTO logs(uID,ip,addTime,jj,xq,`sql`) VALUES(?,?,?,?,?,?) '
CaseMessage='`' 附近有语法错误。
	at org.nutz.dao.impl.sql.run.NutDaoExecutor.exec(NutDaoExecutor.java:94)
	at org.nutz.dao.impl.DaoSupport$DaoExec.invoke(DaoSupport.java:327)
	at org.nutz.dao.impl.sql.run.NutDaoRunner.run(NutDaoRunner.java:59)
	at org.nutz.dao.impl.DaoSupport.run(DaoSupport.java:250)
	at org.nutz.dao.impl.DaoSupport._exec(DaoSupport.java:282)
	at org.nutz.dao.impl.EntityOperator.exec(EntityOperator.java:50)
	at org.nutz.dao.impl.NutDao.insert(NutDao.java:158)
	at com.jxzg.web.IndexAction.checkLogin(IndexAction.java:103)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at org.nutz.mvc.impl.processor.MethodInvokeProcessor.process(MethodInvokeProcessor.java:25)
	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.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:241)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
	at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:957)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:423)
	at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1079)
	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:620)
	at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:318)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.lang.Thread.run(Unknown Source)
Caused by: java.sql.SQLException: '`' 附近有语法错误。
	at net.sourceforge.jtds.jdbc.SQLDiagnostic.addDiagnostic(SQLDiagnostic.java:368)
	at net.sourceforge.jtds.jdbc.TdsCore.tdsErrorToken(TdsCore.java:2816)
	at net.sourceforge.jtds.jdbc.TdsCore.nextToken(TdsCore.java:2254)
	at net.sourceforge.jtds.jdbc.TdsCore.getMoreResults(TdsCore.java:631)
	at net.sourceforge.jtds.jdbc.JtdsStatement.processResults(JtdsStatement.java:584)
	at net.sourceforge.jtds.jdbc.JtdsStatement.executeSQL(JtdsStatement.java:546)
	at net.sourceforge.jtds.jdbc.JtdsPreparedStatement.execute(JtdsPreparedStatement.java:559)
	at org.nutz.dao.impl.sql.run.NutDaoExecutor._runPreparedStatement(NutDaoExecutor.java:268)
	at org.nutz.dao.impl.sql.run.NutDaoExecutor.exec(NutDaoExecutor.java:82)
	... 43 more
log4j: 2016-05-18 16:43:38,635 [http-bio-8080-exec-10] DEBUG org.nutz.mvc.impl.UrlMappingImpl - Found mapping for [GET] path=/login : IndexAction.login(IndexAction.java:36)
log4j: 2016-05-18 16:43:38,636 [http-bio-8080-exec-10] DEBUG org.nutz.ioc.impl.NutIoc - Get 'indexAction'<class com.jxzg.web.IndexAction>

PreparedStatement:
'INSERT INTO logs(uID,ip,addTime,jj,xq,sql) VALUES(?,?,?,?,?,?) '

有中文的引号

在MainSetup类的init方法最前面, 加一句

Daos.CHECK_COLUMN_NAME_KEYWORD = false;

禁用之.

PS: SQLServer什么版本, 看来这个功能还没适配好.

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