熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> Java編程 >> Java開源技術 >> 正文

Struts從零開始二、解決中文亂碼的問題實例[3]

2022-06-13   來源: Java開源技術 

  () 重寫所需的方法加入我們的功能

  具體代碼如下所示

package servlets;

import javaioUnsupportedEncodingException;

import javaxservlethttpHttpServletRequest;

import javaxservlethttpHttpServletResponse;

import orgapachestrutsactionRequestProcessor;

public class EncodingHandler extends RequestProcessor {

public boolean processPreprocess(HttpServletRequest servletRequest

HttpServletResponse serveltResponse) {

try {

servletRequestsetCharacterEncoding(GBK);

Systemoutprintln(請求被處理);

} catch (UnsupportedEncodingException ex) {

exprintStackTrace();

}

return true;

}

}

  () 修改配置文件sturtsconfigxml在其中加入一個名為的元素用以指定我們定制的RequestProcessor類

<?xml version= encoding=UTF?>

<!DOCTYPE strutsconfig PUBLIC //Apache Software Foundation//DTD Struts Configuration //EN http://jakartaapacheorg/struts/dtds/strutsconfig__dtd>

<strutsconfig>

  <formbeans>

    <formbean name=loginActionForm type=formbeansLoginActionForm />

  </formbeans>

  <actionmappings>

<action

path=/login

name=loginActionForm

scope=request

type=actionsLoginAction>

 

[]  []  []  []  []  


From:http://tw.wingwit.com/Article/program/Java/ky/201311/29157.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.