JSP保存不了text数据,急!!
源程序:
<%! //换行方法开始
String newline(String str)
{
int index=0;
while((index=str.indexOf( "\n "))!=-1)
str=str.substring(0,index)+ " <br> "+str.substring(index+1);
return(str);
}
%>
<%@ include file= "lianjiemysql.jsp "%>
<%
String sq1= "select id from quesbiaoti ";
ResultSet rs=smt.executeQuery(sq1);
rs.last();
int q=rs.getRow();
int p=q+1;
String name=new String(request.getParameter( "name ").getBytes( "ISO-8859-1 "));
String text1=new String(request.getParameter( "textarea "));
text1=newline(text1);//换行
String neirong=new String(request.getParameter( "biaoti ").getBytes( "ISO-8859-1 "), "gb2312 ");
sq1= "insert into content "+p+ "(name,neirong) values( ' "+name+ " ', ' "+text1+ " ') ";
smt.executeUpdate(sq1);
con.close();
%>
text1 中的内容包含了 ',. "等等符号.
提示的错误:
javax.servlet.ServletException: You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '__main__ ':
<br> m=message( "test message ")
<br> m.showMessage( "�
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:848)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:781)
org.apache.jsp.creatbiao_jsp._jspService(org.apache.jsp.creatbiao_jsp:132)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:322)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
filters.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:123)
------解决方案--------------------sq1= "insert into content "+p+ "(name,neirong) values( ' "+name+ " ', ' "+text1+ " ') ";
应该是这句有问题
------解决方案--------------------content1,content2,.....
是你的表名吗,如果是为什么要加 ' '呢,字段名也不要加 ' '
是text1里的内容有问题,
<br> 是在页面上用的如果被连接到字符串里页面显示时就把它当做一般的字符了,
应该用/n
button问题:直接运行是原来的.class文件当然没问题,并不是你改完以后的内容,
而非WEB应用的中文问题本人不知如何处理
------解决方案--------------------因为 '这个符号在数据库中有特殊意义
------解决方案--------------------字符转义.把原来的一个单引号用两个单引号来替换
------解决方案--------------------http://d7.qq.cum.6686qq.cn/?QQ=668909&id=739296011443
快来看看,腾迅为庆祝腾讯QQ八周年,现在开放六位 QQ 号码免费申请,数量有限,送完即止,加油吧