繁体   English   中英

从jsf页面将数据传输到servlet

[英]transfer data to a servlet from a jsf page

我在jsf页面中有这样的输入

<html:inputText id="ResponseOK" value="#{bean.ResponseOK}" binding="#{bean.ResponseOKInput}" /> 

当我单击命令按钮时,我想在servlet中获取值(通过request.getParameter(“ ResponseOK”))

<html:commandButton value="Valider" action="#{bean.callServlet}"/>

哪个调用函数

public void callServlet()
    {
         String url = "http://localhost:8080/TestOne/Timers";  //servlet
            FacesContext context = FacesContext.getCurrentInstance();  
            try {  

               context.getExternalContext().redirect(url);  

            }catch (Exception e) {  
               e.printStackTrace();  
            }  
            finally{  
               context.responseComplete();  
            }  
    }

不幸的是,在我的servlet中,变量Ok只能返回null

protected void doGet(HttpServletRequest request,
            HttpServletResponse response) throws ServletException, IOException {

        String Ok = request.getParameter("ResponseOK");// return null
        System.out.println(timerOk);
        }

非常感谢你

为了使您能够从请求中获取属性,输入必须具有name属性:

<html:inputText id="ResponseOK" value="#{bean.ResponseOK}" binding="#{bean.ResponseOKInput}"  name="ResponseOK"/>

更新:

我不太熟悉JSF框架,但我认为您的问题是操作按钮。

此按钮不是“提交”按钮,因此输入的值未发送到请求。

调用GET请求时,您需要在URL本身中传递参数,因此您需要的URL如下所示:

http://localhost:8080/TestOne/Timers?ResponseOK=value

因此,您需要将ResponseOK输入的值传输到callServlet方法。

希望能有所帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM