<%@ page language="java" import="java.util.*" pageEncoding="gbk"%>
<%@ page import="java.sql.*" %>
<%@ page contentType="text/html;charset=gbk" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%
int id=Integer.parseInt(request.getParameter("id"));
int rootid=Integer.parseInt(request.getParameter("rootid"));
%>
<html>
<head>
<title>回复帖子内容</title>
</head>
<body> <form action="ReplyOK.jsp" mothed="post" name="aa">
<input type="hidden" name="id" value="<%=id %>">
<input type="hidden" name="rootid" value="<%=rootid %>">
<table>
<tr>
<td>
<input type="text" name="title" size="81">
</td>
</tr>
<tr>
<td>
<textarea cols="80" rows="12" name="cont"></textarea>
</td>
</tr>
<tr>
<td>
<input type="submit" value="提交">
</td>
</tr>
</table>
</form>
</body>
</html>
以上是写的页面。接下来是处理页面
<%@ page language="java" import="java.util.*" pageEncoding="GBK"%>
<%@ page import="java.sql.*" %>
<%@ page contentType="text/html;charset=GBK" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%
request.setCharacterEncoding("GBK");
int id=Integer.parseInt(request.getParameter("id"));
int rootid=Integer.parseInt(request.getParameter("rootid"));
String title=request.getParameter("title");
String cont=request.getParameter("cont");
Class.forName("com.mysql.jdbc.Driver");
// String url="jdbc:mysql://localhost/bbs2?user=root&password=root";
String url="jdbc:mysql://localhost/bbs2?useUnicode=true&characterEncoding=gbk&user=root&password=root";
Connection conn=DriverManager.getConnection(url);
conn.setAutoCommit(false);
String sql="insert into article values (null,?,?,?,?,now(),0)";
PreparedStatement pstmt=conn.prepareStatement(sql);
Statement stmt=conn.createStatement();
pstmt.setInt(1,id);
pstmt.setInt(2,rootid);
pstmt.setString(3,title);
pstmt.setString(4,cont);
pstmt.executeUpdate();
// stmt.executeUpdate("insert into article values(null,"+rootid+","+'"title"'+","'"cont"'",now(),0"+")")
// stmt.executeUpdate("insert into article values(null,19,'women','neirong',now(),0)");
stmt.executeUpdate("update article set isleaf = 1 where id="+id);
conn.commit();
conn.setAutoCommit(true);
pstmt.close();
stmt.close();
conn.close();
%>
<html>
<head>
<title>回复成功</title></head>
<body>
<%System.out.println(title); %> //测试
<%response.sendRedirect("ShowArticleTree.jsp") ;%>
</body>
</html>
经过测试知道是接收参数出了问题该做的都做了 不知道怎么解决啊。。谢谢了
<%@ page import="java.sql.*" %>
<%@ page contentType="text/html;charset=gbk" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%
int id=Integer.parseInt(request.getParameter("id"));
int rootid=Integer.parseInt(request.getParameter("rootid"));
%>
<html>
<head>
<title>回复帖子内容</title>
</head>
<body> <form action="ReplyOK.jsp" mothed="post" name="aa">
<input type="hidden" name="id" value="<%=id %>">
<input type="hidden" name="rootid" value="<%=rootid %>">
<table>
<tr>
<td>
<input type="text" name="title" size="81">
</td>
</tr>
<tr>
<td>
<textarea cols="80" rows="12" name="cont"></textarea>
</td>
</tr>
<tr>
<td>
<input type="submit" value="提交">
</td>
</tr>
</table>
</form>
</body>
</html>
以上是写的页面。接下来是处理页面
<%@ page language="java" import="java.util.*" pageEncoding="GBK"%>
<%@ page import="java.sql.*" %>
<%@ page contentType="text/html;charset=GBK" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%
request.setCharacterEncoding("GBK");
int id=Integer.parseInt(request.getParameter("id"));
int rootid=Integer.parseInt(request.getParameter("rootid"));
String title=request.getParameter("title");
String cont=request.getParameter("cont");
Class.forName("com.mysql.jdbc.Driver");
// String url="jdbc:mysql://localhost/bbs2?user=root&password=root";
String url="jdbc:mysql://localhost/bbs2?useUnicode=true&characterEncoding=gbk&user=root&password=root";
Connection conn=DriverManager.getConnection(url);
conn.setAutoCommit(false);
String sql="insert into article values (null,?,?,?,?,now(),0)";
PreparedStatement pstmt=conn.prepareStatement(sql);
Statement stmt=conn.createStatement();
pstmt.setInt(1,id);
pstmt.setInt(2,rootid);
pstmt.setString(3,title);
pstmt.setString(4,cont);
pstmt.executeUpdate();
// stmt.executeUpdate("insert into article values(null,"+rootid+","+'"title"'+","'"cont"'",now(),0"+")")
// stmt.executeUpdate("insert into article values(null,19,'women','neirong',now(),0)");
stmt.executeUpdate("update article set isleaf = 1 where id="+id);
conn.commit();
conn.setAutoCommit(true);
pstmt.close();
stmt.close();
conn.close();
%>
<html>
<head>
<title>回复成功</title></head>
<body>
<%System.out.println(title); %> //测试
<%response.sendRedirect("ShowArticleTree.jsp") ;%>
</body>
</html>
经过测试知道是接收参数出了问题该做的都做了 不知道怎么解决啊。。谢谢了
解决方案 »
- 求助hibernate 登陆
- 如何在定时器访问某个action呢??????????
- 我在eclipse中启动tomcat的时候,显示到如下的最后一行之后就不在启动,然后报超时的错,请问如何解决
- mybatis3里面的各个版本具体有什么区别吗?(3.0.3/3.0.4/3.0.5)
- WebLogic APPC tool invocation errors.这个错误如何解决?
- 想系统地看一下正则表达式,请大家推荐几本经典书籍,谢谢
- Socket编程问题
- 散分: .xsl文件中如何动态调用另一个.xsl文件来解析xml文件,急...
- 编码转换问题
- 有人知道吗?在线等?关于findByPrimaryKey()
- JNI如何传递vc中带指针的参数和函数的问题
- 关于下拉列表
byte newstr[]=new byte[str.length()];
for (int i = 0; i < str.length(); i++) {
newstr[i]=(byte)str.charAt(i);
}
return new String(newstr);
}
这个时候title是乱码吗?
*
* @author coombe
*/
public class SetCharacterEncodingFilter implements Filter {
/** 字符编码 */
protected String encoding = null;
/** 过滤器配置器,init初始化过滤器方法中使用它取得web.xml中的配置参数 */
protected FilterConfig filterConfig = null; /**
* 初始化过滤器方法
* @param filterConfig FilterConfig对象,系统初始化本类的实例时调用该方法
* 并传递它,用于读取web.xml中的配置参数。..........
package com.wq.common;
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;public class MyFilter implements Filter {
private String encoding="";
private boolean enable=false;
public void destroy() {
}
public void doFilter(ServletRequest arg0, ServletResponse arg1,
FilterChain arg2) throws IOException, ServletException {
arg0.setCharacterEncoding("utf-8");
arg2.doFilter(arg0, arg1); } public void init(FilterConfig config) throws ServletException {
}
}
二、在web.xml中配置 <filter>
<filter-name>MyFilter</filter-name>
<filter-class>com.wq.common.MyFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>MyFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
String title=new String(request.getParameter("title").getBytes("8859_1"),"gb2312");
你可以测试下.
加上这句
request.setCharacterEncoding("utf-8");