XxxActionForm form = (XxxActionForm)actionForm;
String str = null;
try {
str = new String(form.getStr().getBytes("iso-8859-1"),"GB2312");
} catch (UnsupportedEncodingException ex) {
System.out.println("UnsupportedEncodingException : " +ex.toString());
}
String str = null;
try {
str = new String(form.getStr().getBytes("iso-8859-1"),"GB2312");
} catch (UnsupportedEncodingException ex) {
System.out.println("UnsupportedEncodingException : " +ex.toString());
}
解决方案 »
- 这些配置文件中的类是干嘛使的?
- hql更新语句怎么搞的
- 启动Tomcat就报错,求解
- 做struts2的helloworld 发布时出现的问题
- 父窗口是一个applet,在applet上通过js打开一个小窗口,能否通过js给applet上的字段赋值呢?折腾了两天了实现不了。
- ajax 返回中文乱码
- 问一个比较理论的问题 Struts
- SSH整合注册问题
- 请各位TOMCAT大虾看看,我的TOMCAT哪里不对劲?
- 有人知道 怎么用jtable显示 表格内数据的合计或者列数吗?像dbgrid中合计行那样的,或者其他的解决方案 100分
- 哪里有petstore的源码下载阿?
- 帮帮忙看看我以后的路该怎么走??
public static String isoToGB(String src)
{
String strRet=null;
try{
strRet = new String(src.getBytes("ISO_8859_1"),"GB2312");
}catch(Exception e)
{
}
return strRet;
}
import javax.servlet.http.*;
import java.io.*;
import java.util.*;public class servfilter extends HttpServlet implements Filter {
private FilterConfig filterConfig;
//Handle the passed-in FilterConfig
public void init(FilterConfig filterConfig) {
this.filterConfig = filterConfig;
}
//Process the request/response pair
public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) {
try {
request.setCharacterEncoding("GB2312");
((HttpServletResponse)response).setHeader("Cache-control","no-cache");
response.setHeader("Pragma","No-cache");
response.setHeader("Cache-Control","no-cache");
response.setHeader("Expires","0");
((HttpServletResponse)response).setHeader("Pragram","no-cache");
filterChain.doFilter(request, response);
}
catch(ServletException sx) {
filterConfig.getServletContext().log(sx.getMessage());
}
catch(IOException iox) {
filterConfig.getServletContext().log(iox.getMessage());
}
}
//Clean up resources
public void destroy() {
}
}
下面是一个web.xml文件你用jbuilder写上面的bean的时候会生成一个
<?xml version="1.0" encoding="ISO-8859-1"?><!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd"><web-app>
<display-name>Welcome to Tomcat</display-name>
<description>
Welcome to Tomcat
</description>
<filter>
<filter-name>servfilter</filter-name>
<filter-class>yourbean.servfilter</filter-class>
</filter>
<filter-mapping>
<filter-name>servfilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
把上面的servfilter编译放在你的web-inf/classes/yourbean/下
web.xml放在web-inf/下和classes在一个目录下
在你写的每个jsp页面上
加上<%@page contentType="text/html;charset=GBK"%>
估计你的问题可以解决!
<!--引申子oopliu(岩石) >
protected void process(HttpServletRequest request, HttpServletResponse response) throws java.io.IOException, javax.servlet.ServletException {
/**@todo Override this org.apache.struts.action.ActionServlet method*/
request.setCharacterEncoding("GB2312");//就加着一行一切都解决了
super.process(request, response);
}当然别忘了改一下web.xml里面的配置
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>strutsdemo.myActionServlet</servlet-class>
<init-param>
<param-name>debug</param-name>
<param-value>2</param-value>
</init-param>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>改一下servlet-class标签中的内容就可以