This article is a mirror article of machine translation, please click here to jump to the original article.

View: 14923|Reply: 4

[JavaEE] [Practice] jsp page URL question mark transmission of Chinese garbled characters

[Copy link]
Posted on 12/11/2014 7:07:42 PM | | |
Without further ado, go straight to the code:
[mw_shl_code=java,true] <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@page import="java.net.URLEncoder"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
   
    <title>My JSP 'index.jsp' starting page</title>
        <meta http-equiv="pragma" content="no-cache">
        <meta http-equiv="cache-control" content="no-cache">
        <meta http-equiv="expires" content="0">   
        <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
        <meta http-equiv="description" content="This is my page">
        <!--
        <link rel="stylesheet" type="text/css" href="styles.css">
        -->
  </head>
  
  <body>
  <%--
  <%
  String str = URLEncoder.encode("Chinese","utf-8");
   %>
   --%>
    <a href="test.jsp?name=Wu Soft"> test</a>
  </body>
</html>
[/mw_shl_code]

[mw_shl_code=java,true] <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@page import="java.net.URLDecoder"%>
<%@page import="java.net.URLEncoder"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
   
    <title>My JSP 'test.jsp' starting page</title>
   
        <meta http-equiv="pragma" content="no-cache">
        <meta http-equiv="cache-control" content="no-cache">
        <meta http-equiv="expires" content="0">   
        <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
        <meta http-equiv="description" content="This is my page">
        <!--
        <link rel="stylesheet" type="text/css" href="styles.css">
        -->

  </head>
  
  <body>
  <%
  
  
  String i = new String(request.getParameter("name").getBytes( "iso-8859-1" ), "UTF-8" ); ;
   %>
    <%=i %>
   
  </body>
</html>
[/mw_shl_code]








Previous:3 Huawei HG255D routers have been broken, and I want to save the bricks
Next:JSP has a common method of building object requests
Posted on 12/11/2014 8:04:46 PM |
It's complicated
Posted on 12/11/2014 8:05:15 PM |
URL encoding is done
 Landlord| Posted on 12/11/2014 8:57:54 PM |

So how to do it????
Posted on 12/11/2014 9:21:19 PM |
Encoding and decoding functions for URLs in java
java.net.URLEncoder.encode(String s) and java.net.URLDecoder.decode(String s);

You are at the bottom
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com