问题描述
我有提交包含UTF-8字符串使用Ajax的形式问题。我开发一个的Struts 的Web应用程序:// EN .wikipedia.org /维基/ Apache_Tomcat相对=nofollow> Tomcat的服务器。这是我设置了UTF-8的工作环境:
-
我添加的属性
的URIEncoding =UTF-8useBodyEncodingForURI =真正的
到连接
标记Tomcat的的conf / server.xml中
文件。 -
我有一个
UTF-8_general_ci
数据库 -
我现在用的是一个过滤器,以确保我的请求和响应都设有codeD的UTF-8
包过滤器; 进口java.io.IOException异常; 导入的javax.servlet。*; 公共类UTF8Filter实现过滤器{ 公共无效的destroy(){} 公共无效的doFilter(ServletRequest中要求,ServletResponse的响应的FilterChain链) 抛出IOException异常,ServletException异常{ request.setCharacterEncoding(UTF-8); response.setContentType(text / html的;字符集= UTF-8); chain.doFilter(请求,响应); } 公共无效的init(一个FilterConfig一个FilterConfig)抛出了ServletException { } }
-
我在WEB-INF / web.xml中使用此过滤器
-
我现在用的是下一个code我的JSON响应:
公共静态无效populateWithJSON(HttpServletResponse的响应,JSONObject的JSON) { 字符串CONTENT_TYPE =文/ X-JSON;字符集= UTF-8; response.setContentType(CONTENT_TYPE); response.setHeader(缓存控制,无缓存); 尝试 { 。response.getWriter()写(json.toString()); }赶上(IOException异常E){ 抛出新ApplicationException的(在RetrievedStories提高应用程序异常,E); } }
一切似乎都在正常工作(内容来自数据库的显示正常,我能够提交其存储在UTF-8在数据库表)。问题是,我的无法提交表单使用Ajax 。我使用jQuery,我想这个问题是在Ajax请求缺乏的contentType领域。但是我错了。我有一个非常简单的形式提出意见,其中包含一个ID和一个身体。体场可以在不同的语言,如西班牙语,德语,或什么的。
如果我用含有人体textarea的提交我的表格contraseña
的显示我:
如果我执行的复制位置与参数的萤火虫,编码,似乎已经错了:
<$p$p><$c$c>http://localhost:8080/Cerepedia/corporate/postStoryComment.do?&body=contrase%C3%B1a&id=88这是我的jQuery code:
函数addComment(){
VAR comment_body = $(#postCommentForm文本域)VAL()。
。VAR ITEM_ID = $(#postCommentForm输入:隐藏)VAL();
VAR URL =则rootURL +企业/ postStoryComment.do?;
$。员额(URL,{ID:ITEM_ID,身体:comment_body},
功能(数据){
/ *做的东西的答案* /
},JSON); }
一个提交使用jQuery的一种形式是导致一个错误的服务器端(注意:我使用的)。
javax.servlet.ServletException:org.hibernate.exception.GenericJDBCException:无法执行JDBC批量更新
在org.apache.struts.action.RequestProcessor.processException(RequestProcessor.java:520)
在org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:427)
在org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:228)
在org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
在org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:462)
在javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
在javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
在com.cerebra.cerepedia.security.AuthorizationFilter.doFilter(AuthorizationFilter.java:78)
在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
在com.cerebra.cerepedia.hibernate.HibernateSessionRequestFilter.doFilter(HibernateSessionRequestFilter.java:30)
在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
在filters.UTF8Filter.doFilter(UTF8Filter.java:14)
在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
在org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
在org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
在org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
在org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
在org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
在org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:261)
在org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
在org.apache.coyote.http11.Http11Protocol $ Http11ConnectionHandler.process(Http11Protocol.java:581)
在org.apache.tomcat.util.net.JIoEndpoint $ Worker.run(JIoEndpoint.java:447)
在java.lang.Thread.run(来源不明)
org.hibernate.exception.GenericJDBCException:产生的原因无法执行JDBC批量更新
在org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:103)
在org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:91)
在org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
在org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:249)
在org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:235)
在org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:139)
在org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
在org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
在org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
在org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
在org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
在com.cerebra.cerepedia.item.dao.ItemDAOHibernate.addComment(ItemDAOHibernate.java:505)
在com.cerebra.cerepedia.item.ItemManagerPOJOImpl.addComment(ItemManagerPOJOImpl.java:164)
在com.cerebra.cerepedia.struts.item.ItemAction.addComment(ItemAction.java:126)
在sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)
在sun.reflect.NativeMethodAccessorImpl.invoke(来源不明)
在sun.reflect.DelegatingMethodAccessorImpl.invoke(来源不明)
在java.lang.reflect.Method.invoke(来源不明)
在org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:269)
在org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:170)
在org.apache.struts.actions.MappingDispatchAction.execute(MappingDispatchAction.java:166)
在org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:425)
... 26更多
在第1行'\ xF1a'列'身体':由:java.sql.BatchUpdateException:不正确的字符串值
在com.mysql.jdbc.Server preparedStatement.executeBatch(服务器preparedStatement.java:657)
在com.mchange.v2.c3p0.impl.NewProxy$p$pparedStatement.executeBatch(NewProxy$p$pparedStatement.java:1723)
在org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48)
在org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:242)
... 44更多
26年前,2008年19点54分48秒org.apache.catalina.core.StandardWrapperValve调用
坟墓Servlet.service()对servlet的作用Lanzo郊区excepción
java.sql.BatchUpdateException:不正确的字符串值:'\ xF1a'列'身体'在第1行
在com.mysql.jdbc.Server preparedStatement.executeBatch(服务器preparedStatement.java:657)
在com.mchange.v2.c3p0.impl.NewProxy$p$pparedStatement.executeBatch(NewProxy$p$pparedStatement.java:1723)
在org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48)
在org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:242)
在org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:235)
在org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:139)
在org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
在org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
在org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
在org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
在org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
在com.cerebra.cerepedia.item.dao.ItemDAOHibernate.addComment(ItemDAOHibernate.java:505)
在com.cerebra.cerepedia.item.ItemManagerPOJOImpl.addComment(ItemManagerPOJOImpl.java:164)
在com.cerebra.cerepedia.struts.item.ItemAction.addComment(ItemAction.java:126)
在sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)
在sun.reflect.NativeMethodAccessorImpl.invoke(来源不明)
在sun.reflect.DelegatingMethodAccessorImpl.invoke(来源不明)
在java.lang.reflect.Method.invoke(来源不明)
在org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:269)
在org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:170)
在org.apache.struts.actions.MappingDispatchAction.execute(MappingDispatchAction.java:166)
在org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:425)
在org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:228)
在org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
在org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:462)
在javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
在javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
在com.cerebra.cerepedia.security.AuthorizationFilter.doFilter(AuthorizationFilter.java:78)
在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
在com.cerebra.cerepedia.hibernate.HibernateSessionRequestFilter.doFilter(HibernateSessionRequestFilter.java:30)
在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
在filters.UTF8Filter.doFilter(UTF8Filter.java:14)
在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
在org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
在org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
在org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
在org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
在org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
在org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:261)
在org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
在org.apache.coyote.http11.Http11Protocol $ Http11ConnectionHandler.process(Http11Protocol.java:581)
在org.apache.tomcat.util.net.JIoEndpoint $ Worker.run(JIoEndpoint.java:447)
在java.lang.Thread.run(来源不明)
javax.servlet.ServletException:java.lang.NumberFormatException:空
在org.apache.struts.action.RequestProcessor.processException(RequestProcessor.java:520)
在org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:427)
在org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:228)
在org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
在org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:449)
在javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
在javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
在com.cerebra.cerepedia.security.AuthorizationFilter.doFilter(AuthorizationFilter.java:78)
在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
在com.cerebra.cerepedia.hibernate.HibernateSessionRequestFilter.doFilter(HibernateSessionRequestFilter.java:30)
在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
在filters.UTF8Filter.doFilter(UTF8Filter.java:14)
在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
在org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
在org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
在org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
在org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
在org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
在org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:261)
在org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
在org.apache.coyote.http11.Http11Protocol $ Http11ConnectionHandler.process(Http11Protocol.java:581)
在org.apache.tomcat.util.net.JIoEndpoint $ Worker.run(JIoEndpoint.java:447)
在java.lang.Thread.run(来源不明)
致:java.lang.NumberFormatException:空
在java.lang.Long.parseLong(来源不明)
在java.lang.Long.valueOf(来源不明)
在com.cerebra.cerepedia.struts.item.ItemAction.addComment(ItemAction.java:120)
在sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)
在sun.reflect.NativeMethodAccessorImpl.invoke(来源不明)
在sun.reflect.DelegatingMethodAccessorImpl.invoke(来源不明)
在java.lang.reflect.Method.invoke(来源不明)
在org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:269)
在org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:170)
在org.apache.struts.actions.MappingDispatchAction.execute(MappingDispatchAction.java:166)
在org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:425)
... 26更多
26年前,2008年二十时13分25秒org.apache.catalina.core.StandardWrapperValve调用
坟墓Servlet.service()对servlet的作用Lanzo郊区excepción
java.lang.NumberFormatException:空
在java.lang.Long.parseLong(来源不明)
在java.lang.Long.valueOf(来源不明)
在com.cerebra.cerepedia.struts.item.ItemAction.addComment(ItemAction.java:120)
在sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)
在sun.reflect.NativeMethodAccessorImpl.invoke(来源不明)
在sun.reflect.DelegatingMethodAccessorImpl.invoke(来源不明)
在java.lang.reflect.Method.invoke(来源不明)
在org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:269)
在org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:170)
在org.apache.struts.actions.MappingDispatchAction.execute(MappingDispatchAction.java:166)
在org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:425)
在org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:228)
在org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
在org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:449)
在javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
在javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
在com.cerebra.cerepedia.security.AuthorizationFilter.doFilter(AuthorizationFilter.java:78)
在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
在com.cerebra.cerepedia.hibernate.HibernateSessionRequestFilter.doFilter(HibernateSessionRequestFilter.java:30)
在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
在filters.UTF8Filter.doFilter(UTF8Filter.java:14)
在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
在org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
在org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
在org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
在org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
在org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
在org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:261)
在org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
在org.apache.coyote.http11.Http11Protocol $ Http11ConnectionHandler.process(Http11Protocol.java:581)
在org.apache.tomcat.util.net.JIoEndpoint $ Worker.run(JIoEndpoint.java:447)
在java.lang.Thread.run(来源不明)
你试图加入呼叫之前如下:
$。ajaxSetup({
scriptCharset:UTF-8,
的contentType:应用/ JSON的;字符集= UTF-8
});
该选项此处解释。
的contentType:当发送数据到服务器,使用这种内容类型。默认值是应用程序/ x-WWW的形式urlen codeD,这是适用于大多数情况下。
scriptCharset:只有与JSONP'或'脚本'数据类型,同时GET类型的请求。会强制PTED有一定的字符集间$ P $的要求。仅用于远程和本地内容的字符集的差异。
I am having problems submitting forms which contain UTF-8 strings with Ajax. I am developing a Struts web application which runs in a Tomcat server. This is the environment I set up to work with UTF-8:
I have added the attributes
URIEncoding="UTF-8" useBodyEncodingForURI="true"
into theConnector
tag to Tomcat'sconf/server.xml
file.I have a
utf-8_general_ci
databaseI am using the next filter to ensure my request and responses are encoded in UTF-8
package filters; import java.io.IOException; import javax.servlet.*; public class UTF8Filter implements Filter { public void destroy() {} public void doFilter(ServletRequest request,ServletResponse response, FilterChain chain) throws IOException, ServletException { request.setCharacterEncoding("UTF-8"); response.setContentType("text/html;charset=UTF-8"); chain.doFilter(request, response); } public void init(FilterConfig filterConfig) throws ServletException { } }
I use this filter in WEB-INF/web.xml
I am using the next code for my JSON responses:
public static void populateWithJSON(HttpServletResponse response,JSONObject json) { String CONTENT_TYPE="text/x-json;charset=UTF-8"; response.setContentType(CONTENT_TYPE); response.setHeader("Cache-Control", "no-cache"); try { response.getWriter().write(json.toString()); } catch (IOException e) { throw new ApplicationException("Application Exception raised in RetrievedStories", e); } }
Everything seems to work fine (content coming from the database is displayed properly, and I am able to submit forms which are stored in UTF-8 in the database). The problem is that I am not able to submit forms with Ajax. I use jQuery, and I thought the problem was the lack of contentType field in the Ajax request. But I was wrong. I have a really simple form to submit comments which contains of an id and a body. The body field can be in different languages such as Spanish, German, or whatever.
If I submit my form with body textarea containing contraseña
, Firebug shows me:
If I execute Copy Location with parameters in Firebug, the encoding seems already wrong:
http://localhost:8080/Cerepedia/corporate/postStoryComment.do?&body=contrase%C3%B1a&id=88
This is my jQuery code:
function addComment() {
var comment_body = $("#postCommentForm textarea").val();
var item_id = $("#postCommentForm input:hidden").val();
var url = rooturl+"corporate/postStoryComment.do?";
$.post(url, { id: item_id, body: comment_body } ,
function(data){
/* Do stuff with the answer */
}, "json"); }
A submission of a form with jQuery is causing the next error server side (note I am using Hibernate).
javax.servlet.ServletException: org.hibernate.exception.GenericJDBCException: Could not execute JDBC batch update
at org.apache.struts.action.RequestProcessor.processException(RequestProcessor.java:520)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:427)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:228)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:462)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.cerebra.cerepedia.security.AuthorizationFilter.doFilter(AuthorizationFilter.java:78)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.cerebra.cerepedia.hibernate.HibernateSessionRequestFilter.doFilter(HibernateSessionRequestFilter.java:30)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at filters.UTF8Filter.doFilter(UTF8Filter.java:14)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:261)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:581)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Unknown Source)
Caused by: org.hibernate.exception.GenericJDBCException: Could not execute JDBC batch update
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:103)
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:91)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:249)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:235)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:139)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
at com.cerebra.cerepedia.item.dao.ItemDAOHibernate.addComment(ItemDAOHibernate.java:505)
at com.cerebra.cerepedia.item.ItemManagerPOJOImpl.addComment(ItemManagerPOJOImpl.java:164)
at com.cerebra.cerepedia.struts.item.ItemAction.addComment(ItemAction.java:126)
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.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:269)
at org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:170)
at org.apache.struts.actions.MappingDispatchAction.execute(MappingDispatchAction.java:166)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:425)
... 26 more
Caused by: java.sql.BatchUpdateException: Incorrect string value: '\xF1a' for column 'body' at row 1
at com.mysql.jdbc.ServerPreparedStatement.executeBatch(ServerPreparedStatement.java:657)
at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeBatch(NewProxyPreparedStatement.java:1723)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:242)
... 44 more
26-ago-2008 19:54:48 org.apache.catalina.core.StandardWrapperValve invoke
GRAVE: Servlet.service() para servlet action lanzó excepción
java.sql.BatchUpdateException: Incorrect string value: '\xF1a' for column 'body' at row 1
at com.mysql.jdbc.ServerPreparedStatement.executeBatch(ServerPreparedStatement.java:657)
at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeBatch(NewProxyPreparedStatement.java:1723)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:242)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:235)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:139)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
at com.cerebra.cerepedia.item.dao.ItemDAOHibernate.addComment(ItemDAOHibernate.java:505)
at com.cerebra.cerepedia.item.ItemManagerPOJOImpl.addComment(ItemManagerPOJOImpl.java:164)
at com.cerebra.cerepedia.struts.item.ItemAction.addComment(ItemAction.java:126)
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.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:269)
at org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:170)
at org.apache.struts.actions.MappingDispatchAction.execute(MappingDispatchAction.java:166)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:425)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:228)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:462)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.cerebra.cerepedia.security.AuthorizationFilter.doFilter(AuthorizationFilter.java:78)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.cerebra.cerepedia.hibernate.HibernateSessionRequestFilter.doFilter(HibernateSessionRequestFilter.java:30)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at filters.UTF8Filter.doFilter(UTF8Filter.java:14)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:261)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:581)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Unknown Source)
javax.servlet.ServletException: java.lang.NumberFormatException: null
at org.apache.struts.action.RequestProcessor.processException(RequestProcessor.java:520)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:427)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:228)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:449)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.cerebra.cerepedia.security.AuthorizationFilter.doFilter(AuthorizationFilter.java:78)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.cerebra.cerepedia.hibernate.HibernateSessionRequestFilter.doFilter(HibernateSessionRequestFilter.java:30)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at filters.UTF8Filter.doFilter(UTF8Filter.java:14)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:261)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:581)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NumberFormatException: null
at java.lang.Long.parseLong(Unknown Source)
at java.lang.Long.valueOf(Unknown Source)
at com.cerebra.cerepedia.struts.item.ItemAction.addComment(ItemAction.java:120)
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.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:269)
at org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:170)
at org.apache.struts.actions.MappingDispatchAction.execute(MappingDispatchAction.java:166)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:425)
... 26 more
26-ago-2008 20:13:25 org.apache.catalina.core.StandardWrapperValve invoke
GRAVE: Servlet.service() para servlet action lanzó excepción
java.lang.NumberFormatException: null
at java.lang.Long.parseLong(Unknown Source)
at java.lang.Long.valueOf(Unknown Source)
at com.cerebra.cerepedia.struts.item.ItemAction.addComment(ItemAction.java:120)
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.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:269)
at org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:170)
at org.apache.struts.actions.MappingDispatchAction.execute(MappingDispatchAction.java:166)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:425)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:228)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:449)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.cerebra.cerepedia.security.AuthorizationFilter.doFilter(AuthorizationFilter.java:78)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.cerebra.cerepedia.hibernate.HibernateSessionRequestFilter.doFilter(HibernateSessionRequestFilter.java:30)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at filters.UTF8Filter.doFilter(UTF8Filter.java:14)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:261)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:581)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Unknown Source)
have you tried adding the following before the call :
$.ajaxSetup({
scriptCharset: "utf-8" ,
contentType: "application/json; charset=utf-8"
});
The options are explained here.
contentType : When sending data to the server, use this content-type. Default is "application/x-www-form-urlencoded", which is fine for most cases.
scriptCharset : Only for requests with 'jsonp' or 'script' dataType and GET type. Forces the request to be interpreted as a certain charset. Only needed for charset differences between the remote and local content.
这篇关于我怎样才能让这个code提交UTF-8格式文本区域用jQuery /阿贾克斯工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!