<a href="branchclient.do?p=add&client_name=河蟹"></a>
branchclient.do的Action时这么处理的。BranchclientAction.javapublic ActionForward execute(ActionMapping mapping , ActionForm form , HttpServletRequest request , HttpServletResponse response)
{
String p = request.getParameter("p");
try
{
if( "add".equals(p) )
{
return add(mapping, form, request, response);
}
else if( "findbyclientid".equals(p) )
{
return findByClientId(mapping, form, request, response);
}
else
{
return findByClientId(mapping, form, request, response);
}
}
catch( Exception e )
{
e.printStackTrace();
saveMessage(request, "error.operate");
return mapping.findForward("failure");
}public ActionForward add(ActionMapping mapping , ActionForm form , HttpServletRequest request , HttpServletResponse response) throws Exception
{
return mapping.findForward("add");
}然后上面那个return mapping.findForward("add");在struts.xml文件里进行跳转
struts.xml文件如下
<action
name="branchclientForm"
path="/branchclient"
scope="request"
validate="false"
type="com.dfgg.sms.action.BranchClientAction" >
<forward name="add" path="/BranchClient/BranchClientAdd.jsp" />
<forward name="edit" path="/BranchClient/BranchClientEdit.jsp" />
<forward name="success" path="branchclient.do?s=finddynamic" redirect="true"/>
<forward name="successclient" path="client.do?p=finddynamic" redirect="true"/>
</action>
然后在下面BranchClientAdd.jsp里这样调用最初传的变量client_name=河蟹BranchClientAdd.jsp
<%@ page language="java" pageEncoding="UTF-8" %>
<html:text property="client_name" readonly="true" onclick="fnLaunch();"/>页面BranchClientAdd.jsp取到的property="client_name"就是乱码,英文跟数字不是乱码。
如何解决啊
branchclient.do的Action时这么处理的。BranchclientAction.javapublic ActionForward execute(ActionMapping mapping , ActionForm form , HttpServletRequest request , HttpServletResponse response)
{
String p = request.getParameter("p");
try
{
if( "add".equals(p) )
{
return add(mapping, form, request, response);
}
else if( "findbyclientid".equals(p) )
{
return findByClientId(mapping, form, request, response);
}
else
{
return findByClientId(mapping, form, request, response);
}
}
catch( Exception e )
{
e.printStackTrace();
saveMessage(request, "error.operate");
return mapping.findForward("failure");
}public ActionForward add(ActionMapping mapping , ActionForm form , HttpServletRequest request , HttpServletResponse response) throws Exception
{
return mapping.findForward("add");
}然后上面那个return mapping.findForward("add");在struts.xml文件里进行跳转
struts.xml文件如下
<action
name="branchclientForm"
path="/branchclient"
scope="request"
validate="false"
type="com.dfgg.sms.action.BranchClientAction" >
<forward name="add" path="/BranchClient/BranchClientAdd.jsp" />
<forward name="edit" path="/BranchClient/BranchClientEdit.jsp" />
<forward name="success" path="branchclient.do?s=finddynamic" redirect="true"/>
<forward name="successclient" path="client.do?p=finddynamic" redirect="true"/>
</action>
然后在下面BranchClientAdd.jsp里这样调用最初传的变量client_name=河蟹BranchClientAdd.jsp
<%@ page language="java" pageEncoding="UTF-8" %>
<html:text property="client_name" readonly="true" onclick="fnLaunch();"/>页面BranchClientAdd.jsp取到的property="client_name"就是乱码,英文跟数字不是乱码。
如何解决啊
解决方案 »
- int怎么实现传地址而不是传值?
- 关于hibernate+SQL Server 程序编译错误,请高手看看怎么解决
- Java连接oracle 10g数据库问题
- 这段话什么意思~~~ 苦脑啊!!
- struts标签怎么比较两个变量?
- 是不是看懂了sun的j2eeturial.pdf里的“duke bank”例子,就算学会j2ee了?
- hql语句问题《排序》
- 100分:我从.net转过来,基本熟悉java语言,现在要用jb+weblogic进行ejb开发,哪里有比较好的例子或者什么书比较好?
- 小妹急啊!在线jbuilder9中用tomcat5.0出现"index.jsp": java.lang.NoClassDefFoundError: org/apache/jasper/JspC,
- 用注释的方式映射hibernate,报is not mapped
- javaBean导出为Xml
- session可以做到的,用hibernateTemplate如何做到?
或者像LS说的写个filter拦截/*设置请求编码
如下public class SetCharacterEncodingFilter implements Filter
{
protected String encoding = null;
protected FilterConfig filterConfig = null;
protected boolean ignore = true;
public void destroy()
{
this.encoding = null;
this.filterConfig = null;
}
public void doFilter(ServletRequest request , ServletResponse response , FilterChain chain) throws IOException , ServletException
{
if( ignore || (request.getCharacterEncoding() == null) )
{
String encoding = selectEncoding(request);
if( encoding != null )
request.setCharacterEncoding(encoding);
}
chain.doFilter(request, response);
}
public void init(FilterConfig filterConfig) throws ServletException
{
this.filterConfig = filterConfig;
this.encoding = filterConfig.getInitParameter("encoding");
String value = filterConfig.getInitParameter("ignore");
if( value == null )
this.ignore = true;
else if( value.equalsIgnoreCase("true") )
this.ignore = true;
else if( value.equalsIgnoreCase("yes") )
this.ignore = true;
else
this.ignore = false;
}
protected String selectEncoding(ServletRequest request)
{
return(this.encoding);
}
}
实在不行String str =new String(client_name.getBytes("iso-8859-1"),"utf-8");
然后传str,就不是乱码了
web.xml如下<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>com.dfgg.sms.web.SetCharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
在页面上.<a href="branchclient.do?p=add&client_name=河蟹"></a>
改成.<a href="branchclient.do?p=add&client_name=" + encodeURI(encodeURI('河触'))></a>
在后台.
java.net.URLDecode("client_name","UTF-8")就不会乱了.
把这个写到BranchClientAdd.jspString str =new String((request.getParameter("client_name")).getBytes("iso-8859-1"),"utf-8");
System.out.println(request.getParameter(str));
这样转码很不爽啊
get 没有编码 什么叫对get进行编码
2.更改请求编码
3.万能的。。 str = new String(str.getByte("iso-8859-1"),"UTF-8")