2012-07-24 46 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

相關問題