简体   繁体   中英

transfer data to a servlet from a jsf page

I have an input in my jsf page like this

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

I want to get the value in a servlet (by request.getParameter ("ResponseOK")) when i click on a command button

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

which call a function

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();  
            }  
    }

Unfortunately, in my servlet the variable Ok , return only null

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

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

thank you very much

In order for you to be able to get a property from the request, the input must have the name attribute:

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

UPDATE:

I'm not too familiar with the JSF framework but i think your problem is the action button.

This button is not a submit button so the value of the input is not being sent to the request.

When calling a GET request, you need to pass the parameter in URL itself, so you need the url to look like:

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

So you need to transfer the value of the ResponseOK input to the callServlet method.

Hope that helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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