我正在使用Zk框架并尝试从zhtml页面获取url参数。我试过了:
Executions.getCurrent().getParameter("param");
虽然我在客户端和服务器端的页面编写器中都尝试了zscript,但它对zhtml不起作用。但它正在为zul页面工作。我如何获得zhtml的url参数作为示例:
http://localhost:8080/pystest/reset_password.zhtml?param=xxx
这是我的zhtml页面:
<!DOCTYPE html>
<?taglib uri="http://www.zkoss.org/dsp/web/core" prefix="c" ?>
<html lang="en" xmlns:zk="zk" xmlns:z="zul">
<head>
<meta charset="UTF-8"/>
<title>Reset Password</title>
<meta name="description" content="User reset password page" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<!-- basic styles -->
<link href="css/strap.css" rel="stylesheet" />
<link rel="stylesheet" href="css/font.css" />
<!-- fonts -->
<link rel="stylesheet" href="css/ace-fonts.css" />
<!--styles -->
<link rel="stylesheet" href="css/min.css" />
<link rel="stylesheet" href="css/tlr.css" />
</head>
<body class="pass-layout">
<z:div sclass="main-container" apply="component.ResetPasswordComposer">
<div class="main-content">
<div class="row">
<div class="col-sm-10 col-sm-offset-1">
<div class="pass-container">
<div class="position-relative">
<div id="resetpass-box" class="resetpass-box visible widget-box no-border">
<div class="widget-body">
<div class="widget-main">
<h4 class="header green lighter bigger">
<i class="icon-group blue"></i>
Choose your new password.
</h4>
<form>
<fieldset>
<label class="block clearfix">
<span class="block input-icon input-icon-right">
<z:textbox type="password" class="form-control" placeholder="New password" id="password1" />
<i class="icon-lock"></i>
</span>
</label>
<label class="block clearfix">
<span class="block input-icon input-icon-right">
<z:textbox type="password" class="form-control" placeholder="Verify password" id="password2"/>
<i class="icon-retweet"></i>
</span>
</label>
<div class="space-24"></div>
<div class="clearfix">
<button type="reset" class="width-30 pull-left btn btn-sm">
<i class="icon-refresh"></i>
Reset
</button>
<button id="resetButton" type="button" class="width-65 pull-right btn btn-sm btn-success">
Submit
<i class="icon-arrow-right icon-on-right"></i>
</button>
</div>
</fieldset>
</form>
</div>
<div class="toolbar center">
</div>
</div><!-- /widget-body -->
</div><!-- /resetpass-box -->
</div><!-- /position-relative -->
</div><!-- /pass-container -->
</div><!-- /col-sm-10 col-sm-offset-1 -->
</div><!-- /row -->
</div><!-- /main-content -->
</z:div><!-- /main-container -->
<!-- below script is not working -->
<zk:zscript>
<![CDATA[
alert(Executions.getCurrent().getParameter("param"));
]]>
</zk:zscript>
</body>
</html>
服务器端:
public class ResetPasswordComposer extends GenericForwardComposer<Component> {
/**
*
*/
private static final long serialVersionUID = 1L;
protected Textbox password1;
protected Textbox password2;
@Override
public void doAfterCompose(Component comp) throws Exception {
super.doAfterCompose(comp);
}
public void onClick$resetButton(){
UserOperator userOperator=new UserOperator();
try{
String token=getToken();
System.out.println(token);
}catch(Exception e){
e.printStackTrace();
}
}
private String getToken(){
Execution exec = Executions.getCurrent();
String param=exec.getParameter("param");
return param;
}
}
答案 0 :(得分:1)
你的问题实际上是
private String getToken(){
Execution exec = Executions.getCurrent();
String param=exec.getParameter("param");
return param;
}
仅适用于doAfterCompose
cyclus。
在那里问它并将其保存为全局字符串。