Java web开发遇见的问题整理

Ⅰ、chrome控制台警告:Synchronous XMLHttpRequest on the main thread
解释:这个警告并不是错误,不是逻辑和代码错误;而是浏览器检测出来的一种不建议写法和用法的一种警示,完全不影响程序的执行和正常运行!
大体上的原因是 XMLHttpRequest 【ajax】发送请求,在浏览器js的主线程上,ajax同步发送请求引起的,这样会引起很不好的用户体验,可能导致浏览器卡死等等!
1.AJAX 请求
2.主线程-单线程
3.同步请求引起的阻塞,卡死
解决方法:
1. async: false // 轻轻方式-异步
2. 接受的请求,返回一个html代码段,里面包含了 这样脚本文件引用! 才会出现这种警告!
解决方法:将 提前写入前台页面,从发送过来的HTML 代码段剥离出去,亲测有效!国外网友也是这样总结!
或者引用的外部js脚本文件,写到dom里面,以

console.log('我是外部js内容,现在通过script 标签写到到html里');

或者$.getScript(‘jsUrl’, function() {
// console.log(jsUrl[i] + ” 加载完毕…”);
});


Ⅱ、Uncaught SyntaxError: Unexpected token <
前端页面报错,正常是加载js文件错误。jsp页面会先处理静态的引用页面,也就是说引用文件的地址不是动态参数的页面,当js引用的文件是项目路径下的文件夹时,会报这个错误.
参考:http://z3sm2012.iteye.com/blog/2153588


Ⅲ、SpringMVC下表单提交报错:description The request sent by the client was syntactically incorrect.
可能的原因:
1、提交表单数据类型与model不匹配
2、方法参数顺序不正确
3.Article的属性和你的form提交中的数据类型不 匹配
4 对象类型与model类型不一致
5 model类型不能为private,应为protected/public
6 上传的问题,上传文件大小超出了spring上传的限制

<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">    
    <!-- 设置上传文件的最大尺寸1024字节=1K,这里是10K -->    
    <property name="maxUploadSize">    
        <value>10240</value>    
    </property>  
    <property name="defaultEncoding">    
           <value>UTF-8</value>    
    </property>    
</bean>  

分析:
1、参数指定问题`
如果Controller中定义了参数,而表单内却没有定义该字段,如:

@SuppressWarnings("deprecation")  
@RequestMapping("/hello.do")  
public String hello(HttpServletRequest request,HttpServletResponse response,  
        @RequestParam(value="userName") String user  
){  
    request.setAttribute("user", user);  
    return "hello";  
}  `

不想指定的话,可以改成

@SuppressWarnings("deprecation")  
@RequestMapping("/hello.do")  
public String hello(HttpServletRequest request,HttpServletResponse response,  
        @RequestParam(value="userName",defaultValue="佚名") String user  
){  
    request.setAttribute("user", user);  
    return "hello";  
}  

或者也可以指定该参数是非必须的required=false


Ⅳ、The server encountered an internal error that prevented it from fulfilling this request
springmvc表单提交的时间转换引起的问题
如controller:

@SuppressWarnings("deprecation")  
@RequestMapping("/hello.do")  
public String hello(HttpServletRequest request,HttpServletResponse response,  
        @RequestParam(value="userName",defaultValue="佚名") String user,  
        Date dateTest  
){  
    request.setAttribute("user", user);  
    System.out.println(dateTest.toLocaleString());  
    return "hello";  
}  

而网页是:

<input type="text" name="dateTest" value="2015-06-07">  

这里需要在Controller增加一个转换器

@InitBinder    
public void initBinder(WebDataBinder binder) {    
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");    
    dateFormat.setLenient(false);    
    binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, false));    
}  

参考:http://blog.csdn.net/xiaomin1991222/article/details/50980825

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值