在我的申请中有一个注册表,提交后,它将邮寄给管理员以接受/拒绝注册。
在邮件发送时,会附加一个唯一的 key 以及接受按钮
。单击此按钮后,将在 Controller 中触发 actionListener
,并且我想从查询字符串中读取唯一的键值,但我得到的是 null,尽管 URL http://localhost:8080/BridgeFront/app/AproveReq.xhtml?activityId=LFGP13005
包含查询字符串参数。我做错了什么吗?如果有人知道请告诉我。
我想说的一件事是,在我的项目中我使用的是 spring 框架。
在 web.xml 中我写了这个用于过滤:
<filter>
<filter-name>openSessionInView</filter-name>
<filter-class>org.springframework.orm.hibernate4.support.OpenSessionInViewFilter</filter-class>
</filter>
AproveReq.xhtml
的代码如下:
<h:form>
<p:commandButton value="Aprove" action="#{aproveDeny.xyz}"/>
<p:commandButton value="Deny"/>
</h:form>
Controller 如下:
@ManagedBean(name = "aproveDeny")
@RequestScoped
public class AproveDeny{
@ManagedProperty("#{param.activityId}")
private String activityId;
public void xyz(){
System.out.println("-------+++"+getActivityId());
}
public String getActivityId() {
return activityId;
}
public void setActivityId(String activityId) {
this.activityId = activityId;
}}
这样设置邮件正文(MimeMessage):
MimeMessageHelper mimeMessageHelper = new MimeMessageHelper(mimeMessage, true);
mimeMessageHelper.setTo("xxxxxx.xxxx@gmail.com");
StringBuilder text = new StringBuilder();
StringBuilder text = new StringBuilder();
text.append("<html>");
text.append("<body>");
text.append("<a href="+URL+"?activityId="+ActivityId+">Accept Or Deny request.."+"</a>");
text.append("</body>");
text.append("</html>");
mimeMessageHelper.setText(text.toString(), true);
最佳答案
您不必使用具有 View 作用域的托管 Bean。首先将其更改为请求范围,然后将参数注入(inject)到类中的变量中。
@ManagedBean(name = "activityEntryController")
@RequestScoped
public class ActivityEntryController{
@ManagedProperty(value="#{param.activityId}")
private String activityId;
public void aproveActivityEntryReq(ActionEvent event){
// make your work
}
}
如果您的 url 中有多个参数,则应向类添加一个变量,并使用 ManagedProperty 对其进行注释,例如,如果您还想在 url 参数中发送一封电子邮件
@ManagedProperty(value="#{param.email}")
private String email;
关于java - 未从查询字符串获取值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16185544/