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());
}
留言列表