简体   繁体   中英

Unknown characters are being printed in Java

I am working on Java platform with IDE (jdeveloper). I am using simple text box in one jsp and sending its string to another jsp where I get that string and simply display that there, it works fine until the user puts some special character. When user puts special character the character is displayed as unknown character shown as ?. I understand the encoding issues, that's why UTF-8 is being used but still the problem is there.

Can anybody suggest me about it. I want to give freedom to the user to type anything in any language.

This will accept any character The pageEncoding at the top will tell the server to decode the contents to UTF-8 and then send

In File.html

  <%@page pageEncoding="UTF-8"%>
  <html>
  <form action="hello.jsp" method="POST" >
        <input type="text" name="name" />
        <input type="submit" name="Submit" value="Submit name" />

In Hello.jsp file Here setCharacterEncoding will encode the contents.

  <%
    request.setCharacterEncoding("UTF-8");
    String name   = request.getParameter("name");
    Hello <%=name%><br>
  %>

This will echo the characters sent from the File.html Hope this will help.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM