[英]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.