| |

VerySource

 Forgot password?
 Register
Search
View: 814|Reply: 7

The page is garbled, master please help!

[Copy link]

1

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-1-29 23:00:01
| Show all posts |Read mode
<% @ page pageEncoding = "UTF-8"%>
<% @ page contentType = "text / html; charset = UTF-8"%>
<% @ taglib uri = "/ tags / struts-bean" prefix = "bean"%>
<% @ taglib uri = "/ tags / struts-html" prefix = "html"%>
<% @ taglib uri = "/ tags / struts-logic" prefix = "logic"%>
<% @ taglib uri = "/ tags / struts-tiles" prefix = "tiles"%>
<% @ taglib uri = "/ tags / struts-nested" prefix = "nested"%>

<! DOCTYPE HTML PUBLIC "-// W3C // DTD HTML 4.01 Transitional // EN">
<html>
<head>
<meta http-equiv = "Content-Type" content = "text / html; charset = UTF-8">
<title> TESTSTRUTS </ title>
</ head>
<body>

<html: form action = "/ hello">
User account: <html: text property = "userName" /> <html: errors property = "userName" /> <br/>
User password: <html: text property = "userPasswrd" /> <html: errors property = "userPasswrd" /> <br/>
<html: submit value = "Submit" /> <html: cancel value = "Cancel" />
</ html: form>
<logic: present name = "personbean" scope = "request">
<h1>
<bean: message key = "hello.jsp.page.hello" />
<bean: write name = "personbean" property = "userName" />
</ h1>
<h2>
<bean: write name = "personbean" property = "userPasswrd" />
</ h2>
</ logic: present>
</ body>
</ html>

The result: "User name:" becomes "鐢 ㄦ 埛 宁 愬 佛 锛&# 65533;"
May I ask what is the reason? Checked a lot of information! not solved!
Reply

Use magic Report

1

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

 Author| Post time: 2020-3-6 05:15:01
| Show all posts
Just top it yourself
Reply

Use magic Report

0

Threads

3

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-3-6 19:30:01
| Show all posts
Try gb2312
Reply

Use magic Report

0

Threads

9

Posts

8.00

Credits

Newbie

Rank: 1

Credits
8.00

 China

Post time: 2020-3-8 11:00:02
| Show all posts
1.Encoding issues:
  (1) First determine if the JSP page header has: <% @ page contentType = "text / html; charset = GBK"%>
  (2) Transcoding like this:
     String param = new String (request.getParameter ("param"). GetBytes ("ISO-8859-1"), "GBK");
  (3) Add a filter character filter, the specific method:

      First add the class:

import javax.servlet.Filter;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.FilterChain;
import java.io.IOException;
import org.apache.log4j.Logger;
import java.net.URLEncoder;

/ ** * // **
 * Chinese string filtering in request
 * /

public class SetEncodingFilter
    implements Filter ... {
  private Logger logger = Logger.getLogger (this.getClass ());

  public void init (FilterConfig filterConfig) throws ServletException ... {
  }

  public void doFilter (ServletRequest request, ServletResponse response,
                       FilterChain chain) throws IOException, ServletException ... {
    logger.info ("Request transcoding filter ====================);
    request.setCharacterEncoding ("gb2312");
    chain.doFilter (request, response);
  }

  public void destroy () ... {
  }
}
     Register the class to XML:

  <filter>
    <filter-name> Set Encoding </ filter-name>
    <filter-class> SetEncodingFilter </ filter-class>
  </ filter>
  <filter-mapping>
    <filter-name> Set Encoding </ filter-name>
    <url-pattern> / * </ url-pattern>
  </ filter-mapping>
 

  (4) If the parameters are passed through "a.jsp? Param = Chinese", you need:
     a. Transcode the parameters before passing them: java.net.URLEncoder.encode (param);
       Use java.net.URLDncoder.dncode (param) for the value; then switch back to Chinese
     b. Find this section in your Tomcat directory-> conf directory-> server.xml:

       <Connector
port = "8080" maxThreads = "150" minSpareThreads = "25" maxSpareThreads = "75"
               enableLookups = "false" redirectPort = "8443" acceptCount = "100"
               debug = "0" connectionTimeout = "20000"
               disableUploadTimeout = "true" <!-Add this parameter here-> URIEncoding = "gb2312"
 />
 

  (5) The database is garbled, first make sure that you are Chinese before inserting the database, the solution:

     Add useUnicode = true&characterEncoding = GBK to the database connection URL of the database.

     If garbled characters appear when reading, use the second method to solve it.

http://blog.csdn.net/lip009/archive/2006/09/07/1192022.aspx#521755
Reply

Use magic Report

0

Threads

4

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 United States

Post time: 2020-4-7 20:15:02
| Show all posts
Learn
Reply

Use magic Report

0

Threads

6

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 Invalid IP Address

Post time: 2020-4-8 16:15:01
| Show all posts
Try this instead
<% @ page contentType = "text / html; charset = gb2312" language = "java"%>
<! DOCTYPE HTML PUBLIC "-// W3C // DTD HTML 4.01 Transitional // EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv = "Content-Type" content = "text / html; charset = gb2312">
Reply

Use magic Report

0

Threads

6

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 Invalid IP Address

Post time: 2020-4-10 22:45:01
| Show all posts
Is this individual?
If it is individual (that is, the other jsp shows normal) then I suggest you
String param = new String (request.getParameter ("param"). GetBytes ("ISO-8859-1"), "UTF-8");
Should be fine
Reply

Use magic Report

0

Threads

7

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

Post time: 2020-4-11 10:45:01
| Show all posts
Before you return the result to the foreground, use String str = new String (str.getBytes ("ISO-8859-1"))
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list