jsp中文乱码
<%@ page language="java" contentType="text/html; charset=gbk"
pageEncoding="gbk"%>
<%@ page import="java.sql.*" %>
<%
String action = request.getParameter("action");
if (action != null&& action.equals("post")) {
request.setCharacterEncoding("gbk");
String title = request.getParameter("title");
System.out.println(title);
String cont = request.getParameter("cont");
cont = cont.replaceAll("\n","<br>");
Class.forName("com.mysql.jdbc.Driver");
String url = "jdbc:mysql://localhost/bbs?user=root&password=root";
Connection conn = DriverManager.getConnection(url);
conn.setAutoCommit(false);
String sql = "insert into article values(null,0,?,?,?,now(),0)";
PreparedStatement psta = conn.prepareStatement(sql,Statement.RETURN_GENERATED_KEYS);
psta.setInt(1,-1);
psta.setString(2,title);
psta.setString(3,cont);
psta.executeUpdate();
ResultSet rsKey = psta.getGeneratedKeys();
rsKey.next();
int key = rsKey.getInt(1);
rsKey.close();
String sql1 = "update article set rootid =? where id =?";
PreparedStatement psta1 = conn.prepareStatement(sql1);
psta1.setInt(1,key);
psta1.setInt(2,key);
psta1.executeUpdate();
conn.commit();
conn.setAutoCommit(true);
psta.close();
psta1.close();
conn.close();
response.sendRedirect("ShowArticleTree.jsp");
}
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gbk">
<title>Insert title here</title>
</head>
<body>
<form action="Post.jsp" method ="post">
<input type="hidden" name="action" value="post">
<table>
<tr>
<td><input type="text" size=80 name="title"/></td>
</tr>
<tr>
<td><textarea cols="80" rows="20" name="cont"></textarea></td>
</tr>
<tr>
<td><input type="submit" value="提交"/></td>
</tr>
</table>
</form>
</body>
</html>发现插入数据库的中文是乱码,怎么回事?
...全文
相关推荐
JSP中文乱码问题解决总结
JSP中文乱码问题解决总结,个人收集,一次放出,减少大家的查找时间。
Tomcat环境下JSP中文乱码问题的解决
Tomcat环境下JSP中文乱码问题的解决
解决jsp页面中文乱码问题
NULL 博文链接:https://prowl.iteye.com/blog/483854
JSP中文乱码处理JSP中文乱码处理
jsp中文乱码的处理<br>页面显示 表单提交 数据库操作JSP中文乱码处理
JSP出现中文乱码问题解决方法详解
在介绍方法之前我们首先应该清楚具体的问题有哪些,笔者在本博客当中论述的JSP中文乱码问题有如下几个方面:页面乱码、参数乱码、表单乱码、源文件乱码。下面来逐一解决其中的乱码问题。 一、JSP页面中文乱码 在JSP页面中,中文显示乱码有两种情况:一种是HTML中的中文乱码,另一种是在JSP中动态输出的中文乱码。 先看一个JSP程序: <%@ page language=java import=java.util.* %> <html> <head> <title>中文显示示例</title> </head> <body> 这是一个中文显示示例: <% String str



