昨天遇到一个问题让我困惑了半天,window.open("url?param="+paramvalue)传递参数出现乱码,以前从没有遇到过这种问题,在客房端显示是正常的,可是到服务端就是乱码,不管用什么方式转码都不行,经过和同事一翻调试,最后想到了一个js在客户端转码的函数,escape(str);但是传到服务端仍然是乱码,必须在服务端进行解码。服务端执行request.setCharacterEncoding("utf-8");或GBK,这样传过来的参数就不用转码也是中文了。唉,总算功夫没有白费!
window.open("WindowCustomerListAction?username="+encodeURIComponent(form1.name.value), "customerList", "width=550,height=250,scrollbars=yes,resizable=yes,status=yes");
服务端
public class WindowCustomerListAction extends AbstractAction{
/**
* (non-Javadoc)
*
* @see org.apache.cocoon.acting.Action#act(org.apache.cocoon.environment.Redirector,
* org.apache.cocoon.environment.SourceResolver, java.util.Map,
* java.lang.String, org.apache.avalon.framework.parameters.Parameters)
*/
public Map act(Redirector redirector, SourceResolver resolver,
Map objectMode, String source, Parameters param) throws Exception {
// TODO Auto-generated method stub
Request request = ObjectModelHelper.getRequest(objectMode);
String userName = request.getParameter("username")==null?"":request.getParameter("username").trim();
//获得要显示的页码
String showpage = request.getParameter("showpage") == null ? "1"
: request.getParameter("showpage");
//客户信息接口
ThProcessCustomerDAO customerDao = (ThProcessCustomerDAO) AppSqlConfig
.getDaoManagerInstance().getDao(ThProcessCustomerDAO.class,
"sqlmap");
//获得客户列表
ThProcessCustomerExample example = new ThProcessCustomerExample();
example.setName("%"+userName+"%");
example.setName_Indicator(ThProcessCustomerExample.EXAMPLE_LIKE);
List customerlist = customerDao.selectByExample(example);
int count = customerlist.size();
//分页
PageControl pageControl = new PageControl();
pageControl.setPageSize(10);
pageControl.setRowCount(count);
pageControl.setRequestUrl("WindowCustomerListAction?userName="+userName+"&showpage=");
pageControl.setShowPage(Integer.parseInt(showpage));
request.setAttribute("pageControl", pageControl);
request.setAttribute("customerlist", customerlist);
return null;
}
}
posted on 2006-08-02 08:18
选宝网an9 阅读(2885)
评论(2) 编辑 收藏 所属分类:
JAVA