close
request.SetCharacterEncoding("utf-8");

javac -encoding Big5 *java

[JSP程式語法]
以下紅色字部分即是要特別注意的地方!
<%@ page contentType="text/html; charset=big5" language="java" import="java.sql.*" errorPage="" %>
<%
request.setCharacterEncoding("big5");
String name=request.getParameter("name");
String email=request.getParameter("email");
String subject=request.getParameter("subject");
String message=request.getParameter("message");
try{
Class.forName("org.gjt.mm.mysql.Driver");
Connection con=DriverManager.getConnection("jdbc:mysql://localhost/guestbook?useUnicode=true&characterEncoding=utf8","root","");
Statement stmt=con.createStatement();
String sqlstr="insert into guestbook(name, email, subject, message)values('"+name+"','"+email+"','"+subject+"','"+message+"')";
stmt.executeUpdate(sqlstr);

stmt.close();
con.close();
}
catch(ClassNotFoundException e)
{
out.println(e.getMessage());
}
catch(SQLException e)
{
out.println(e.getMessage());
}

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 roczen2007 的頭像
    roczen2007

    roczen2007

    roczen2007 發表在 痞客邦 留言(0) 人氣()