您的位置:首页 > Web前端 > HTML

operamasks url传参 乱码, operamasks xhtml页面url 传参 中文乱码

2010-11-05 10:34 351 查看
页面一wew.xhtml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE HTML PUBLIC "" "">
<f:view xmlns="http://www.w3.org/1999/xhtml" xmlns:f="http://java.sun.com/jsf/core"
xmlns:w="http://www.apusic.com/jsf/widget" xmlns:layout="http://www.apusic.com/jsf/layout"
xmlns:h="http://java.sun.com/jsf/html" xmlns:ajax="http://www.apusic.com/jsf/ajax"
renderKitId="AJAX">
<w:head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</w:head>
<w:page title="Insert title here">

<w:iframe id="frame1" style="width: 100%;height: 100%;" name="content1" frameborder="no"></w:iframe>

</w:page>
</f:view>

对应WewBean ,红色部分很重要,不然会出现乱码

package com;

import java.io.Serializable;

import org.operamasks.faces.annotation.BeforeRender;
import org.operamasks.faces.annotation.Bind;
import org.operamasks.faces.annotation.ManagedBean;
import org.operamasks.faces.annotation.ManagedBeanScope;
import org.operamasks.faces.component.html.impl.UIIFrame;
/**
*
* This managed bean is generated automatically
*/
@ManagedBean(name="wewBean", scope=ManagedBeanScope.SESSION)
public class WewBean implements Serializable {
@Bind
private UIIFrame frame1;

@BeforeRender
public void init(boolean isPost) throws Exception {
if (frame1.getSrc() == null || "".equals(frame1.getSrc())) {
frame1.setSrc("wew1.xhtml?terminalId="+java.net.URLEncoder.encode("中文", "utf-8"));
frame1.load(frame1.getSrc());
}
}
}

页面二wew1.xhtml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE HTML PUBLIC "" "">
<f:view xmlns="http://www.w3.org/1999/xhtml" xmlns:f="http://java.sun.com/jsf/core"
xmlns:w="http://www.apusic.com/jsf/widget" xmlns:layout="http://www.apusic.com/jsf/layout"
xmlns:h="http://java.sun.com/jsf/html" xmlns:ajax="http://www.apusic.com/jsf/ajax"
renderKitId="AJAX">
<w:head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</w:head>
<w:page title="Insert title here">
<h:outputText id="paramvalue"></h:outputText>
</w:page>
</f:view>

对应Wew1Bean

package com;

import java.io.Serializable;
import java.util.Map;

import javax.faces.context.FacesContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.operamasks.faces.annotation.BeforeRender;
import org.operamasks.faces.annotation.Bind;
import org.operamasks.faces.annotation.ManagedBean;
import org.operamasks.faces.annotation.ManagedBeanScope;
import org.operamasks.faces.annotation.SaveState;
/**
*
* This managed bean is generated automatically
*/
@ManagedBean(name="wew1Bean", scope=ManagedBeanScope.SESSION)
public class Wew1Bean implements Serializable {
@Bind
@SaveState
private String paramvalue = "";

@BeforeRender
public void init(boolean isPost) throws Exception {
Map<String, String> valueMap = FacesContext.getCurrentInstance()
.getExternalContext().getRequestParameterMap();
String param = valueMap.containsKey("terminalId") ? String
.valueOf(valueMap.get("terminalId")) : null;
System.out.println(param);
paramvalue = param;

}
}

这样就好了!如果你有更好的传参方法,谢谢共同奉献!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: