日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

jboss url路径_在JBoss的服务器端正确解码URL参数

發(fā)布時間:2023/12/3 编程问答 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 jboss url路径_在JBoss的服务器端正确解码URL参数 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

jboss url路徑

我今天花了很多時間來弄清楚如何在運行在JBoss上的JSF應(yīng)用程序中(使用JBoss 7 Final)強制正確解碼編碼的字符。 當您有例如通過URL傳遞中文字符時,就會發(fā)生此問題。 假設(shè)您有指點事件,編碼為%E6%8C%87%E4%BA%8B。 令人驚訝,但是這些字符以????o?的形式到達服務(wù)器端。 服務(wù)器使用ISO-8859-1自動解碼它們。 因此,如果您嘗試像這樣自己解碼,則沒關(guān)系:

FacesContext fc = FacesContext.getCurrentInstance(); String param = fc.getExternalContext().getRequestParameterMap().get(name); String decodedParam = java.net.URLDecoder.decode(param, "UTF-8");

這無濟于事,因為字符已經(jīng)被錯誤地解碼,并且您從請求參數(shù)映射中獲得了已經(jīng)被錯誤解碼的字符。 如果您在頁面上也沒有幫助

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>

要克服此錯誤,您需要做兩件事:特殊的字符編碼過濾器和JBoss的standalone.xml中的配置。 過濾器應(yīng)同時為請求和響應(yīng)設(shè)置配置的編碼。

public class CharacterEncodingFilter implements Filter {/** The default character encoding to set for request / response. */private String encoding = null;/** The filter configuration object. */private FilterConfig filterConfig;/** Should a character encoding specified by the client be ignored? */private boolean ignore = true;public void destroy() {encoding = null;filterConfig = null;}public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException,ServletException {// conditionally select and set the character encoding to be usedif ((ignore || (request.getCharacterEncoding() == null)) && (encoding != null)) {request.setCharacterEncoding(encoding);response.setCharacterEncoding(encoding);}// pass control on to the next filterchain.doFilter(request, response);}public void init(FilterConfig filterConfig) throws ServletException {this.filterConfig = filterConfig;this.encoding = filterConfig.getInitParameter("encoding");String value = filterConfig.getInitParameter("ignore");this.ignore = ((value == null) || value.equalsIgnoreCase("true") || value.equalsIgnoreCase("yes"));} }

注意:如果僅設(shè)置請求的編碼,則無濟于事。 您還應(yīng)該通過response.setCharacterEncoding(encoding)將其設(shè)置為響應(yīng)。 web.xml中的配置看起來像

<filter><filter-name>CharacterEncodingFilter</filter-name><filter-class>xyz.mypackage.CharacterEncodingFilter</filter-class><init-param><description>override any encodings from client</description><param-name>ignore</param-name><param-value>true</param-value></init-param><init-param><description>the encoding to use</description><param-name>encoding</param-name><param-value>UTF-8</param-value></init-param> </filter> <filter-mapping><filter-name>CharacterEncodingFilter</filter-name><url-pattern>*.jsf</url-pattern> </filter-mapping>

現(xiàn)在,您必須在關(guān)閉<extensions>標記之后直接將以下系統(tǒng)屬性添加到standalone.xml中:

<system-properties><property name="org.apache.catalina.connector.URI_ENCODING" value="UTF-8"/><property name="org.apache.catalina.connector.USE_BODY_ENCODING_FOR_QUERY_STRING" value="true"/> </system-properties>

從文檔中:

  • org.apache.catalina.connector.URI_ENCODING指定%xx解碼URL后用于解碼URI字節(jié)的字符編碼。 如果未指定,將使用ISO-8859-1。
  • org.apache.catalina.connector.USE_BODY_ENCODING_FOR_QUERY_STRING指定是否應(yīng)將contentType中指定的編碼用于URI查詢參數(shù),而不是使用org.apache.catalina.connector.URI_ENCODING。 出現(xiàn)此設(shè)置是為了與Tomcat 4.1.x兼容,其中在contentType中指定的編碼或使用Request.setCharacterEncoding方法顯式設(shè)置的編碼也用于URL中的參數(shù)。 默認值為false。

現(xiàn)在,JBoss看起來為響應(yīng)設(shè)置了字符編碼,并使用它來解碼URL參數(shù)。 希望此信息可以幫助您節(jié)省時間。

參考: 在JBoss中 ,我們的JCG合作伙伴 Oleg Varaksin在軟件開發(fā)博客Thoughts上 正確解碼了URL參數(shù) 。

翻譯自: https://www.javacodegeeks.com/2013/07/proper-decoding-of-url-parameters-on-the-server-side-in-jboss.html

jboss url路徑

總結(jié)

以上是生活随笔為你收集整理的jboss url路径_在JBoss的服务器端正确解码URL参数的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。