jboss url路径_在JBoss的服务器端正确解码URL参数
jboss url路徑
我今天花了很多時間來弄清楚如何在運行在JBoss上的JSF應用程序中(使用JBoss 7 Final)強制正確解碼編碼的字符。 當您有例如通過URL傳遞中文字符時,就會發生此問題。 假設您有指點事件,編碼為%E6%8C%87%E4%BA%8B。 令人驚訝,但是這些字符以????o?的形式到達服務器端。 服務器使用ISO-8859-1自動解碼它們。 因此,如果您嘗試像這樣自己解碼,則沒關系:
這無濟于事,因為字符已經被錯誤地解碼,并且您從請求參數映射中獲得了已經被錯誤解碼的字符。 如果您在頁面上也沒有幫助
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>要克服此錯誤,您需要做兩件事:特殊的字符編碼過濾器和JBoss的standalone.xml中的配置。 過濾器應同時為請求和響應設置配置的編碼。
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"));} }注意:如果僅設置請求的編碼,則無濟于事。 您還應該通過response.setCharacterEncoding(encoding)將其設置為響應。 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>現在,您必須在關閉<extensions>標記之后直接將以下系統屬性添加到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字節的字符編碼。 如果未指定,將使用ISO-8859-1。
- org.apache.catalina.connector.USE_BODY_ENCODING_FOR_QUERY_STRING指定是否應將contentType中指定的編碼用于URI查詢參數,而不是使用org.apache.catalina.connector.URI_ENCODING。 出現此設置是為了與Tomcat 4.1.x兼容,其中在contentType中指定的編碼或使用Request.setCharacterEncoding方法顯式設置的編碼也用于URL中的參數。 默認值為false。
現在,JBoss看起來為響應設置了字符編碼,并使用它來解碼URL參數。 希望此信息可以幫助您節省時間。
翻譯自: https://www.javacodegeeks.com/2013/07/proper-decoding-of-url-parameters-on-the-server-side-in-jboss.html
jboss url路徑
總結
以上是生活随笔為你收集整理的jboss url路径_在JBoss的服务器端正确解码URL参数的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 联想笔记本电脑官网(联想笔记本电脑官网售
- 下一篇: 中单小鱼人符文天赋符文天赋加点图s6(新