2012-07-24 86 views
0

我有一个输入在我的JSF页面类似这样的将数据传输到一个servlet

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

我想(通过用request.getParameter(“ResponseOK”))时获得一个servlet的价值我点击一个命令按钮

<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变好了,回复O NLY空

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

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

非常感谢你

+0

而不是重定向,你不应该做一个rd.forward(请求,响应); – Satya 2012-07-24 10:40:02

+0

@Satya感谢您的帮助,但requestDispatcher允许从另一个servlet获取数据,并且在这里我需要从我的jsf页面获取数据。 – ulquiorra 2012-07-24 10:49:51

回答

1

为了让你能够得到从请求的属性,输入的名称必须为属性:

<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方法。

希望有所帮助。

+0

感谢您的帮助,但jsf输入文本的name属性不存在,仅适用于jsp。所以我不能检索属性> _ < – ulquiorra 2012-07-24 11:15:08

+0

看看生成的html,它是否有名称属性? – Tomer 2012-07-24 11:18:28

+0

编辑我的答案。 – Tomer 2012-07-24 11:25:21

相关问题