From the web form after the execution of the request, the lines in Russian come in ruined form. In the servlet itself, I directly ask

request.setCharacterEncoding("utf-8"); 

The web page with the form also has all the necessary attributes:

 <meta http-equiv="content-type" content="text/html; charset=utf-8"/> <%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8" %> 

In the preprocessing of the request, there are two filters: one to download files, the second to logging, their effect on the request is excluded, since the first one checks the enctype and only works if it is multipart, the second does not do any transformations with the data of the request object.

Web application uses the following components:

  1. Java (TM) SE Runtime Environment (build 1.6.0_06-b02), Java HotSpot (TM) Client VM (build 10.0-b22, mixed mode, sharing)
  2. Tomcat 6 -server -Xmx1024m -Djavax.servlet.request.encoding = UTF-8 -Dfile.encoding = UTF-8

Adding

This is a servlet request handler.

 protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try { request.setCharacterEncoding("utf-8"); response.setCharacterEncoding("utf-8"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } String folder = getActionName(request); Action action = factory.create(folder); String url = null; try { url = action.perform(request, response); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } if (url != null) getServletContext().getRequestDispatcher(url).forward(request, response); } 

Then it sends the request & response to the appropriate class, the handler of which is shown below.

 public String perform(HttpServletRequest request, HttpServletResponse response) { InputStream iS = MainServlet.context.getResourceAsStream("/WEB-INF/UserManagement/WebForm.xml"); Properties webform = new Properties(); try { webform.loadFromXML(iS); } catch (IOException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } Integer uGID = null; try { if(request.getSession().getAttribute("GID")!=null) uGID = (Integer)request.getSession().getAttribute("GID"); else uGID = 0; } catch (Exception e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } if (uGID==1) { Integer UID = null; Integer GID = null; String action = request.getParameter("action"); //Locale usual = Locale.getDefault(); //Locale.setDefault(new Locale("ru","RU")); String Name = request.getParameter("Name"); String Login = request.getParameter("Login"); String Password = request.getParameter("Password"); //Locale.setDefault(usual); String q = ""; MyDB oracle = new MyDB(MyDB.Oracle); CallableStatement cs; ResultSet rs; try { if (request.getParameter("UID")!=null) { UID = Integer.parseInt(request.getParameter("UID")); } if (request.getParameter("GID")!=null) { GID = Integer.parseInt(request.getParameter("GID")); } } catch (NumberFormatException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } try { if(action.equals("remove")) { cs = oracle.conn.prepareCall("begin deleteusers(:1); end;"); cs.setString(1,Integer.toString(UID)); cs.execute(); } else if(action.equals("adduser")) { q = "begin adduser(:1,:2,:3,:4,:5); end;"; cs = oracle.conn.prepareCall(q); cs.setString(1,Login); cs.setString(2,Password); cs.setString(3,Integer.toString(GID)); cs.setString(4,Name); cs.registerOutParameter(5, Types.INTEGER); cs.execute(); System.out.println("Login:"+Login+" Password:"+Password+" Name:"+Name); if(cs.getInt(5)>0) { request.getSession().setAttribute("errorMsg", webform.getProperty("AlreadyExists")); } else if(cs.getInt(5)==-1) { request.getSession().setAttribute("errorMsg", webform.getProperty("Empty")); } } else if(action.equals("edituser")) { q = "begin ediuser (:1,:2,:3,:4,:5,:6); end;"; cs = oracle.conn.prepareCall(q); cs.setString(1,Integer.toString(UID)); cs.setString(2,Login); cs.setString(3,Password); cs.setString(4,Name); cs.setString(5,Integer.toString(GID)); cs.registerOutParameter(6, Types.INTEGER); cs.execute(); if(cs.getInt(6)>0) { request.getSession().setAttribute("errorMsg", webform.getProperty("ErrorChanging")); } else if(cs.getInt(6)==-1) { request.getSession().setAttribute("errorMsg", webform.getProperty("Empty")); } } } catch (SQLException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } //System.out.println(q); oracle.close(); } else { request.getSession().setAttribute("errorMsg", webform.getProperty("AccessDenied")); } return "/UserManagement.jsp"; } 

and finally, UserManagement.jsp itself

 <div><h2><%=webform.getProperty("Adding")%></h2></div> <form action="${urlForm}"> <table cellpadding="10" cellspacing="10"> <tr><td><%=webform.getProperty("Name")%></td><td><input type="text" class="text" name="Name"></td></tr> <tr><td><%=webform.getProperty("Login")%></td><td><input type="text" class="text" name="Login"></td></tr> <tr><td><%=webform.getProperty("Password")%></td><td><input type="password" class="text" name="Password"></td></tr> <tr><td><%=webform.getProperty("Group")%></td><td> <select name="GID"> <% for(Integer key: groups.keySet()){%> <option value="<%=key%>"><%=groups.get(key)%></option> <% } %> </select> </td></tr> <tr><td colspan="2"><input class="button" type="submit" value="<%=webform.getProperty("Add").trim()%>"></td></tr> </table> <input type="hidden" name="action" value="adduser"> </form> 
  • Try in the browser to see what kind of encoding he put. - Jenkamen
  • Here I tried to do it like yours .. I have the system encoding UTF-8, so for the purity of the experiment I did windows-1251 everywhere ... and no defects. Chose UTF-8 everywhere .. everywhere UTF-8 and works .. - cy6erGn0m
  • That's about the multipart in more detail .. than you parse multipart-data? Or your form does not use all the same multipart? - cy6erGn0m
  • 2 cy6erGn0m The form does not use multipart. - This is to ensure that the filter does not affect the query parameters. 2 evm The browser is worth UTF-8 - Alex
  • Well then, these are some miracles. The code in the studio. - cy6erGn0m

3 answers 3

Your form does not have a method. So you have got? Passing passwords via GET is very bad, use POST. Perhaps the problem with the encoding will go away by itself.

And another thing: using Java code in JSP is an old and very bad tone. Use EL-expressions and JSTL. Compare, for example, the cycle:

 <c:forEach var="e" values="${groups}"> <option value="${e.key}">${e.value}</option> </c:forEach> 

UPD: if GET was required necessarily, then it would be possible to try to add the attribute accept-charset to the form tag.

  • So it somehow influenced? Help or no effect? - cy6erGn0m
  • Yes, it really was the method attribute. - Alex
  • Close the question and mark the answer so that the question does not hang in the unanswered. - cy6erGn0m
  • Did not find how to close - Alex
  • Under the evaluation of the answer there is a hand down, and under it - a daw - the right answer. After that, you can close .. at the bottom of the question there are links to edit | close | anxiety. Click to close. - cy6erGn0m

The answer is given, nevertheless, I’ve recently hit it, I’ll share - firefox sometimes corrects the encoding via GET - in particular, if the encoding of the receiving page is not specified, the byte-code cp1251 is transmitted. Keep in mind for the future

 <? echo !empty($_GET['t'])?$_GET['t']:''; // мне выдало ромбики:) ?> 

    Check the file encoding.

    • File encoding does not ultimately affect anything. - cy6erGn0m