java - JSP file encoding in TomCat -
i have use tomcat 8.00 , intellij idea 14.0 , h2 database. when text textfields in register form (cyrillic) records in database this:
it's importand made these configurations.
this index.jsp file
<%@ page contenttype="text/html;charset=utf-8" language="java" pageencoding="utf-8" %> <html> <head> <title>home</title> <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
this servlet
public class registerservlet extends httpservlet { protected void dopost(httpservletrequest request, httpservletresponse response) throws servletexception, ioexception { string username = request.getparameter("usernamereg"); string pass = request.getparameter("passreg"); string name = request.getparameter("firstnamereg"); string lastname = request.getparameter("lastnamereg"); string email = request.getparameter("emailreg"); request.setattribute("username", username); studentbean regstudent; try { regstudent = new registerdao().registerstudent(username, pass, name, lastname, email); request.getservletcontext().getrequestdispatcher("/index.jsp").forward(request, response); } catch (sqlexception e) { e.printstacktrace(); } }
and registerdao class:
public class registerdao { connection conn = null; preparedstatement state = null; //resultset res = null; public studentbean registerstudent(string username, string pass, string name, string lastname, string email) throws sqlexception{ studentbean result = null; string sql = "insert student values(null, ?, ?, ?, ?, ?)"; try { conn = dbconnection.getinstance().getconnect(); state = conn.preparestatement(sql); state.setstring(1, username); state.setstring(2, pass); state.setstring(3, name); state.setstring(4, lastname); state.setstring(5, email); state.execute(); } catch (sqlexception e) { system.out.println("Нулл поинт"); e.printstacktrace(); }finally { if(state != null){ state.close(); } } dbconnection.getinstance().disconnect(); return result; } }
in english works fine. think jsp file not corectly saved in utf-8 , still use default intellij encoding.
i grateful ideas resolve problem.
best regards, d. balamjiev
you can try add in servlet.
response.setcharacterencoding("utf-8")
Comments
Post a Comment