アプリ版:「スタンプのみでお礼する」機能のリリースについて

改善方法はありますか。

public class daytime extends HttpServlet {
protected String decodeString(String str){
try{
byte[] byteData = str.getBytes("ISO_8859_1");
str = new String(byteData, "Shift_JIS");
}catch(UnsupportedEncodingException e){
return null;
}
return str;
}
public void doGet(HttpServletRequest request ,HttpServletResponse response) response.setContentType("text/html;charset=Shift_JIS");
PrintWriter out = response.getWriter();
String tmp;
String name = "";
tmp = request.getParameter("name");
Calendar cal = Calendar.getInstance();
out.println("<html lang=\"ja\" >");
out.println("<head>");
out.println("<title>ContextParam Example</title>");
out.println("<style>");
out.println("</style>");
out.println("<meta http-equiv=\"Content-Type\" Content=\"text/html;charset=Shift_JIS\">"); out.println("</head>");
out.println("<body>");
out.println("<table>");

out.println("<p>");
Connection conn = null;
String url = "jdbc:mysql://localhost/list2";
String user = "list2";
String password = "list2";
out.println("</table>");
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
out.println("Mysqlのロードに成功");
conn = DriverManager.getConnection(url, user, password);
Statement stmt = conn.createStatement();
String sql = "SELECT * FROM goods";
ResultSet rs = stmt.executeQuery(sql);
out.println("<table>");
while(rs.next()){
out.println("<tr>");
out.println("<td>" +rs.getInt("id") + "</td>");
out.println("<td>" +rs.getString("name") + "</td>");
out.println("<td>" +rs.getString("mail") + "</td>");
out.println("<td>" +rs.getInt("price") + "</td>");
out.println("<form method=\"GET\" action=\"./daytime3\">");
out.println("<input type=\"hidden\" name=\"id\" value=\""+ rs.getInt("id") + "\">");
out.println("<td><input type=\"submit\" value=\"更新\"></td>"); out.println("<td><input type=\"submit\" value=\"削除\"></td>"); out.println("</form>");
out.println("</tr>");
}
out.println("</table>");
rs.close();
stmt.close();
}
catch (ClassNotFoundException e){
out.println("ClassNotFoundException:" + e.getMessage());
}catch (SQLException e){
out.println("SQLException:" + e.getMessage());
} catch (Exception e){
out.println("Exception:" + e.getMessage());
}finally{
try{
if (conn != null){
conn.close();
out.println("DBに切断");
}else{
out.println("データベースの接続ない");
}
}catch (SQLException e){
}
}
out.println("</p>");
out.println("<tr>");
out.println("</tr>");
out.println("<A HREF='/dddd/daytime2'>登録</A>");
out.println("<A HREF='/dddd/daytime5'>アンケート</A>");
out.println("<div style=\"font-size: 40px; text-align: center; font-weight: bold\">"); out.println(cal.get(Calendar.YEAR) + "/" + (cal.get(Calendar.MONTH) + 1) + "/" + cal.get(Calendar.DATE) + " " + cal.get(Calendar.HOUR_OF_DAY) + ":" + cal.get(Calendar.MINUTE));
out.println("</div>");
out.println("</body>");
out.println("</html>");

protected String decodeString(String str){
try{
byte[] byteData = str.getBytes("ISO_8859_1");
str = new String(byteData, "Shift_JIS");
}catch(UnsupportedEncodingException e){
return null;
}
return str;
}
}
}

A 回答 (1件)

パソコン内に閉じたプログラムなら、S-JIFで可能。


サーバを経由するなら、UTF-8くらいの文字コード変換は必須。

この回答への補足

追加、直すところがありましたら教えてください。

補足日時:2015/01/21 10:06
    • good
    • 0

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!