页面编码有没有设为:iso8859_1
解决方案 »
- JAVA浏览图片并将图片保存到指定的路径(急)
- struts2 手工编译的问题
- package javelin.jsp does not exist
- 求:动态从数据库取出数据,然后在JSP页面上用下拉框〈html:select〉进行显示
- 在JSF中,怎样实现Select下拉框onchange事件触发后台bean的方法被调用。
- 挑战新手的问题~!~!
- 关于线程的一些不明白的地方。恳请详解
- JSP中判断session过期问题
- 时间的问题!在线等!
- 一个数据库更新的问题困扰ING着我,请大家帮忙看看~
- 关于JSP中JDBC conntion SQL SERVER写库的问题。
- 到指定时间,程序能自动运行
import java.lang.*;
public class dbcon {
Connection conn = null;
public Connection getConn(){ try {
Class.forName("oracle.jdbc.driver.OracleDriver");
conn = DriverManager.getConnection("jdbc:oracle:thin:@76.48.56.7:1521:test", "wfsw", "wfsw");
}
catch (Exception e) {
e.printStackTrace();
}
return conn;
}
}
/**********
定义一个对中文字符进行编码转换的方法
*/
public String ex_chinese(String str){
if(str==null||str.length()==0){
str ="" ;
}
else{
try {
str = new String(str.getBytes("iso-8859-1"),"GBK") ;
}
catch (Exception ex) {
}
}
return str ;
}试试这个<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<html>
<head>
<title>del fwjg</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<jsp:useBean id="beancon" scope="page" class="com.wfsw.dbcon" />
<body>
<%
/*
*String url = 上一页URL
*String db = 数据库名 <-必要参数
*String tjzd = 条件字段 <-必要参数
*String t = 条件字段值 <-必要参数
*String xgzd = 修改字段 <-必要参数
*String x = 修改字段值 <-必要参数
*String msg = 提示信息
*/
try {
String url = request.getHeader("Referer"); //上一页URL
String db = beancon.ex_chinese(request.getParameter("db")); //数据库名
String tjzd = beancon.ex_chinese(request.getParameter("tjzd")); //条件字段
String t = beancon.ex_chinese(request.getParameter("t")); //条件字段值
String xgzd = beancon.ex_chinese(request.getParameter("xgzd")); //修改字段
String x = beancon.ex_chinese(request.getParameter("x")); //修改字段值
Connection con = beancon.getConn();
Statement stmt = con.createStatement();
String sql="update "+db+" set "+xgzd+" = '"+x+"' where "+tjzd+"="+t;
stmt.executeUpdate(sql);
stmt.close();
con.close();
//判断是否显示msg
if (!(request.getParameter("msg")==null)){
String msg=beancon.ex_chinese(request.getParameter("msg"));
out.print("<script language='JavaScript' type='text/JavaScript'>alert (\""+msg+"\");self.location=\""+url+"\";</script>");
}else{
response.sendRedirect(url);
}
}
catch(java.sql.SQLException ex){
out.print(ex);
}
catch(Exception e){
out.println(e);
}
%></body>
</html>