2011-09-07 113 views
4

我正在使用jsf 1.1和icefaces 1.8。我有一个PartsInv.jsp页面和一个托管的PartsInv.java bean。我已经尝试了几个基于我碰到的谷歌点击的课程,并且感觉自己越来越接近了,但我无法完全理解它。这是我有:如何获取查询字符串

HttpServletRequestWrapper hsrw; 
String rcVal = hsrw.getAttribute("rc").toString(); 

当然hsrw,但没有正确实例化。我真的不知道如何(或者什么绕到它)。任何帮助,将不胜感激。

编辑:基于Jigar的回答,我已经更新了我的代码如下:

HttpServletRequest hsr = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest(); 

    if(hsr.getAttribute("rc") != null) 
    { 
     try 
     { 
      int rc = Integer.parseInt(hsr.getAttribute("rc").toString()); 
      this.SOM_RC.setValue(rc); 
      this.changeRC(null); 
     } 
     catch(NumberFormatException nfe) 
     { 
      this.lblStatus.setValue("eASP error, please see an administrator."); 
      return; 
     } 
    } 

EDIT2:好了,我使用了错误的方法。 hsr.getParameter()的伎俩

回答

4

为JSF如果你想有一个具体的参数去

HttpServletRequest request = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest(); 
+0

非常感谢!我欠你一个;) –

+0

欢迎您也考虑麦道的 –

3

,它注入到你的bean:如果bean要引用的参数从在

<managed-bean> 
    <managed-bean-name>fooBean</managed-bean-name> 
    <managed-bean-class>foo.FooBean</managed-bean-class> 
    <managed-bean-scope>request</managed-bean-scope> 
    <managed-property> 
    <property-name>bar</property-name> 
    <property-class>java.lang.String</property-class> 
    <value>#{param.bar}</value> 
    </managed-property> 
</managed-bean> 

范围更广,您可以从外部环境中查找(parameter; parameters)。

如果您确实需要查询字符串,则可以使用表达式#{request.queryString}从请求中注入that

+0

Thx的伟大的额外信息!这将派上用场 –