iT邦幫忙

0

使用tomcat8、jsp,update Oracle DB中文變亂碼

我使用tomcat8、jsp,update Oracle DB,中文變亂碼,爬文設定如下,但仍有問題苦惱許久,請各位大神指點,謝謝!!

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" import="java.sql.*" %>

<%
class PageFunctions extends Object {
	
	public void action (Connection conn, javax.servlet.jsp.JspWriter out) throws Exception {
		
		request.setCharacterEncoding("UTF-8");
		
		String a[] =request.getParameterValues("id");
        String b[] =request.getParameterValues("reason");
		PreparedStatement st=null;

try{

if(a !=null) {
for(int i=0;i<a.length;i++) {
	String r_id = a[i];
	String r_reason = b[i];


String sql = "UPDATE TABLE SET REASON=? WHERE ID=?";
conn.setAutoCommit(false);
st = conn.prepareStatement(sql);
st.setString(1, r_reason); 
st.setString(2, r_id);

out.println(r_id);
out.println(r_reason);

st.executeUpdate();
conn.commit();
}
}
 
}
catch (Exception e) {
e.printStackTrace();
}
}
}

%>


<!DOCTYPE html>
<html class="h-100">
   <head>
   </head>
   <body>
    <%
       request.setCharacterEncoding("UTF-8");
	   response.setContentType("text/html; charset=UTF-8");
     %>
               <%
                  try {


                    PageFunctions funcs = new PageFunctions();
                    DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
                    Connection conn = DriverManager.getConnection("jdbc:oracle", "AAA", "BBB");
					
                    funcs.action(conn, out);
					conn.commit();
				    conn.close();
					conn = null;
					} 
		            catch (Exception ex) {
						out.println("    Error: " + ex.getLocalizedMessage() + "<br><br>\n");
						}
               %>
   </body>
</html>

尚未有邦友回答

立即登入回答