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:
- Java (TM) SE Runtime Environment (build 1.6.0_06-b02), Java HotSpot (TM) Client VM (build 10.0-b22, mixed mode, sharing)
- 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>