[code=HTML<%@ page language="java" contentType="text/html;charset=gb2312"%>
<%@page import="java.util.*,java.sql.*,my.*"%>
<html>
<head>
</head>
<body>
<%
request.setCharacterEncoding("gb2312");
String str=request.getParameter("id");
if(str==null || str.trim().equals(""))
{
out.print("error");
return;
}
String str1=request.getParameter("rootid");
if(str1==null || str1.trim().equals(""))
{
out.print("error");
return;
}
int id=0;
int rootId=0;
try{
id=Integer.parseInt(str);
rootId=Integer.parseInt(str1);
}catch(NumberFormatException e){
out.print("error again");
return;
}
%> <form action="replydeal.jsp" method="post">
<input type="hidden" name="pid" value="<%=id %>"/>
<input type="hidden" name="rootid" value="<%=rootId %>"/>
标题:<input type="text" name="title"/><br>
内容: <textarea name="cont" rows="20" cols="80"></textarea>
<input type="submit" value="提交"/>
</form>
</body>
</html>[/code]<%@ page language="java" contentType="text/html;charset=gb2312"%>
<%@page import="java.util.*,java.sql.*,my.*"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'replideal.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
--> </head>
<%
String str=request.getParameter("pid");
if(str==null || str.trim().equals(""))
{
out.print("error");
return;
}
String str1=request.getParameter("rootid");
if(str1==null || str1.trim().equals(""))
{
out.print("error");
return;
}
int pid=0;
int rootId=0;
try{
pid=Integer.parseInt(str);
rootId=Integer.parseInt(str1);
}
catch(NumberFormatException e){
out.print("error again");
return;
}
request.setCharacterEncoding("gb2312");
String title=request.getParameter("title");
String cont=request.getParameter("cont");
out.print(title);
Connection conn=DB.getConn();
conn.setAutoCommit(false);
String sql="insert into article values (null,?,?,?,?,now(),?)";
PreparedStatement pstmt=DB.getPstmt(conn,sql);
pstmt.setInt(1,pid);
pstmt.setInt(2,rootId);
pstmt.setString(3,title);
pstmt.setString(4,cont);
pstmt.setInt(5,0);
pstmt.executeUpdate(); Statement stmt=DB.getStmt(conn);
String q=null;
try{
q="update article set isleaf=1 where id="+pid;
stmt.executeUpdate(q);
conn.commit();
conn.setAutoCommit(true); }catch(SQLException e){
out.print(q);//update article set isleaf=1 where id=25 3秒
}
DB.close(stmt);
DB.close(pstmt);
DB.close(conn);
%>
<body>
<script language="JavaScript1.2" type="text/javascript">
<!--
// Place this in the 'head' section of your page. function delayURL(url, time) {
setTimeout("top.location.href='" + url + "'", time);
}//--></script>
3秒后自动跳转,如果没有跳转请点击下面连接
<a href="MyJsp.jsp">跳转</a>
<script type="text/javascript">
delayURL("MyJsp.jsp",3000);
</script>
</body>
</html>这为什么会有乱码,
request.setCharacterEncoding("gb2312");
String title=request.getParameter("title");
String cont=request.getParameter("cont");
out.print(title);这边打印出来的是乱码,插入数据库里的也是乱码,其它页面都不会这样,同样都是 request.setCharacterEncoding("gb2312");,别的页面都不会有乱码问题,我还特地写了两个test页面测试下,也不会有乱码啊
<%@page import="java.util.*,java.sql.*,my.*"%>
<html>
<head>
</head>
<body>
<%
request.setCharacterEncoding("gb2312");
String str=request.getParameter("id");
if(str==null || str.trim().equals(""))
{
out.print("error");
return;
}
String str1=request.getParameter("rootid");
if(str1==null || str1.trim().equals(""))
{
out.print("error");
return;
}
int id=0;
int rootId=0;
try{
id=Integer.parseInt(str);
rootId=Integer.parseInt(str1);
}catch(NumberFormatException e){
out.print("error again");
return;
}
%> <form action="replydeal.jsp" method="post">
<input type="hidden" name="pid" value="<%=id %>"/>
<input type="hidden" name="rootid" value="<%=rootId %>"/>
标题:<input type="text" name="title"/><br>
内容: <textarea name="cont" rows="20" cols="80"></textarea>
<input type="submit" value="提交"/>
</form>
</body>
</html>[/code]<%@ page language="java" contentType="text/html;charset=gb2312"%>
<%@page import="java.util.*,java.sql.*,my.*"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'replideal.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
--> </head>
<%
String str=request.getParameter("pid");
if(str==null || str.trim().equals(""))
{
out.print("error");
return;
}
String str1=request.getParameter("rootid");
if(str1==null || str1.trim().equals(""))
{
out.print("error");
return;
}
int pid=0;
int rootId=0;
try{
pid=Integer.parseInt(str);
rootId=Integer.parseInt(str1);
}
catch(NumberFormatException e){
out.print("error again");
return;
}
request.setCharacterEncoding("gb2312");
String title=request.getParameter("title");
String cont=request.getParameter("cont");
out.print(title);
Connection conn=DB.getConn();
conn.setAutoCommit(false);
String sql="insert into article values (null,?,?,?,?,now(),?)";
PreparedStatement pstmt=DB.getPstmt(conn,sql);
pstmt.setInt(1,pid);
pstmt.setInt(2,rootId);
pstmt.setString(3,title);
pstmt.setString(4,cont);
pstmt.setInt(5,0);
pstmt.executeUpdate(); Statement stmt=DB.getStmt(conn);
String q=null;
try{
q="update article set isleaf=1 where id="+pid;
stmt.executeUpdate(q);
conn.commit();
conn.setAutoCommit(true); }catch(SQLException e){
out.print(q);//update article set isleaf=1 where id=25 3秒
}
DB.close(stmt);
DB.close(pstmt);
DB.close(conn);
%>
<body>
<script language="JavaScript1.2" type="text/javascript">
<!--
// Place this in the 'head' section of your page. function delayURL(url, time) {
setTimeout("top.location.href='" + url + "'", time);
}//--></script>
3秒后自动跳转,如果没有跳转请点击下面连接
<a href="MyJsp.jsp">跳转</a>
<script type="text/javascript">
delayURL("MyJsp.jsp",3000);
</script>
</body>
</html>这为什么会有乱码,
request.setCharacterEncoding("gb2312");
String title=request.getParameter("title");
String cont=request.getParameter("cont");
out.print(title);这边打印出来的是乱码,插入数据库里的也是乱码,其它页面都不会这样,同样都是 request.setCharacterEncoding("gb2312");,别的页面都不会有乱码问题,我还特地写了两个test页面测试下,也不会有乱码啊
解决方案 »
- select标签
- 在jsp中如何把JSon数据添加到下拉框中
- hibernate 中连接 mysql 执行count(*) 麻烦先进来看下
- 急!!如何实现内容的上移下移的排序功能
- 小弟刚学servlet,遇到一个问题急求高人指点
- 服务器重启,session还存在??
- 请问yui2.6.0 treeview 中的dblClickEvent怎么用,多谢
- 大家来探讨一个普通问题?
- Servlet是怎么跟JSP结合使用的?
- ApplicationContext.getBean()获取service无异常,但结果为null,获取dao可以得到实体
- 请高手进来帮帮忙
- 求助 HttpSessionBindingListener 的用法
如果是UTF-8,我建议你全部统一编码为UTF-8
----- charset=utf-8