Hello, there is a jsp page in which there is a field where you need to enter a string, passes it all to a servlet that outputs it. But if the data is in Russian, it outputs nonsense. How to fix it?
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="utf-8"%> <html > <body > <FORM action="testform" method=POST> <H3> Введи что-нибудь < INPUT type="text" name="Имя проекта" value="-задать!-"> </H3> <INPUT type="submit" value="Принять"> <BR> </FORM> </body> </html> and servlet
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String name; String value; PrintWriter writer = response.getWriter(); writer.print("<HTML lang=\"ru-Ru\"><HEAD>"); writer.print("<TITLE>Результат</TITLE>"); writer.print("</HEAD><BODY></BODY>"); Enumeration names = request.getParameterNames(); while (names.hasMoreElements()) { name = (String)names.nextElement(); value = request.getParameterValues(name)[0]; writer.print("<H1>name = " + name + " value = " + value+"</H1>"); } writer.print("< /HTML>"); }
response.setCharacterEncoding("UTF-8")correct, but I recommend that you read about Filter - iGreetYou