现在本人有这么个需求,把文本框的name属性设置为含有中文字符
如:
<input type="text" name="姓名1" value="" />
但是在提交表单后,使用
request.getParameter("姓名1")  得到的值为null我想是不是因为name属性不支持中文的原因。
当然,这不是我提问的目的。这想知道: 要达到我的这种需求应该如何实现? 
先谢谢各位了。

解决方案 »

  1.   

    最好不要这么做,其实你写的没错,估计是编码错了,你把jsp的编码改成GBK试试
      

  2.   

    111.jsp
    <%@ page language="java" import="java.util.*" pageEncoding="gbk"%>
    <html>
      <body>
       <%out.println(request.getParameter("中文")); %>
      </body>
    </html>
    222.jsp
    <%@ page language="java" import="java.util.*" pageEncoding="gbk"%>
    <html>
      <body>
       <form action="111.jsp" method="post" name="111">
       <input type="text" name="中文" value="">
       <input type="submit" value="111">
       <br>
      </body>
    </html>
    filterimport java.io.IOException;
    import javax.servlet.Filter;
    import javax.servlet.FilterChain;
    import javax.servlet.FilterConfig;
    import javax.servlet.ServletException;
    import javax.servlet.ServletRequest;
    import javax.servlet.ServletResponse;
    public class SetCharacterEncodingFilter implements Filter { protected String encoding = null; protected FilterConfig filterConfig = null; public void destroy() { this.encoding = null;
    this.filterConfig = null; } public void doFilter(
    ServletRequest request,
    ServletResponse response,
    FilterChain chain)
    throws IOException, ServletException {
    if ((request.getCharacterEncoding() == null)) {
    String encoding = selectEncoding(request);
    if (encoding != null)
    request.setCharacterEncoding("gbk");
    } chain.doFilter(request, response); }
    public void init(FilterConfig filterConfig) throws ServletException {
    this.filterConfig = filterConfig;
    this.encoding = "gbk";
    }
    protected String selectEncoding(ServletRequest request) { return (this.encoding); }
    }
    web.xml
    <filter>
         <display-name>SetCharacterEncodingFilter</display-name> 
    <description>SetCharacterEncodingFilter</description> 
    <filter-name>SetCharacterEncodingFilter</filter-name>
    <filter-class>arts.setencode.SetCharacterEncodingFilter</filter-class>
    </filter>
    <filter-mapping>
    <filter-name>SetCharacterEncodingFilter</filter-name>
    <url-pattern>/*</url-pattern>
    </filter-mapping>我亲自试过了 绝对可行
      

  3.   

    就是编码格式的问题,GBK可以解决
      

  4.   

    我现在是修改代码,象wuzeng2002() 这样改是不允许的.
    不过两样得谢谢你.
      

  5.   

    这个问题通过修改name中不含中文解决。