zoukankan      html  css  js  c++  java
  • struts2中form提交到action中的中文参数乱码问题解决办法(包括取中文路径)

    我的前台页是这样的:

    <body>
          <form action="test.action" method="post">
              测试文件:<input type="file" id="doc" name="path" value=""/>
              <input type="submit" value="提交" onclick=""/>
          </form>
      </body>

    Action:

    package com;

    import java.io.UnsupportedEncodingException;


    import com.opensymphony.xwork2.ActionSupport;

    @SuppressWarnings("serial")
    public class TestAction extends ActionSupport
    {
        private String path;

        public String getPath()
        {
            return path;
        }

        public void setPath(String path)
        {
            this.path = path;
        }


        public String test() throws Exception
        {
            System.out.println(path.replace("\", "\\"));
            return SUCCESS;
        }

    }


    刚开始的时候一选中文路径就输出???.
    后来终于找到解决方法.
    在struts.xml文件中加上:
    为了解决form提交到action中的中文参数乱码问题。
     
    1.在struts2-core-2.0.0-SNAPSHOT.jar包中路径为struts2-core-2.0.6orgapache struts2
    有一个default.properties 文件,把struts.i18n.encoding=UTF-8改为

    struts.i18n.encoding=GBK 


    2.或者在struts.xml文件内添加常量: 

    <constant name="struts.i18n.encoding" value="GBK"/>

    我设置value="GB2312"


    我当然是用的第二种方法,简单方便.

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE struts PUBLIC
        "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
        "http://struts.apache.org/dtds/struts-2.0.dtd">
    <struts>
        <constant name="struts.i18n.encoding" value="GBK"/>
        <package name="com" extends="struts-default">
            <action name="test" class="com.TestAction" method="test">
                <result>/ok.jsp</result>
            </action>
        </package>
    </struts>


    呵呵,终于解决了.希望对大家有些帮助. 

    http://www.blogjava.net/supercrsky/articles/170549.html

  • 相关阅读:
    Spring aop 记录操作日志 Aspect 自定义注解
    winSCP连接FTP没有上传的权限
    Ubantu下安装FTP服务器
    设置ubantu的软件源地址
    Ubantu中安装sublime
    Ubantu 新建用户后没有生成对应文件夹
    Spring aop 记录操作日志 Aspect
    Java中如何获取spring中配置文件.properties中属性值
    java中获取ServletContext常见方法
    解决:“java.lang.IllegalArgumentException: error at ::0 can't find referenced pointcut myMethod”问题!
  • 原文地址:https://www.cnblogs.com/yuhuameng/p/5448402.html
Copyright © 2011-2022 走看看