I have a JSF 2.0 web project, my web have a form and it have to do:
-
Get the parametres of the form and save it in a Bean (Done)
-
Get this information from the servlet:
- Remote Address:
- Remote Host:
- Locale:
- Content Type:
- Boundary:
- Content Length:
- Character Encoding:
-
Insert the Bean data and Servlet data in a table of a database (waiting step 2)
I dont know much about Servlets in JSF, i dont need if i have to make one or not. I only have the code of that but in JSP:
String informe="";
Enumeration a = request.getHeaderNames();
while(a.hasMoreElements() ){
String h = a.nextElement().toString();
informe += h+": "+request.getHeader(h)+"\n";
}
a = request.getAttributeNames();
while(a.hasMoreElements() ){
String h = a.nextElement().toString();
informe += h+": "+request.getHeader(h)+"\n";
}
informe += "Remote Address: "+request.getRemoteAddr()+"\n";
informe += "Remote Host: "+request.getRemoteHost()+"\n";
informe += "Locale: "+request.getLocale()+"\n";
informe += "Content Type: "+request.getContentType()+"\n";
informe += "Content Length: "+request.getContentLength()+"\n";
.....
..
I don’t know how I can get the request information in JSF and wich steps I have to do. I readed a lot of pages but I think that I don’t need all things that they do.
The
HttpServletRequestobject is in JSF available byExternalContext#getRequest().The
ExternalContextby the way also offers some direct methods to get the desired information. Check the methods starting withgetRequestXxx()such asgetRequestHeaderMap(),getRequestContentType(), etc in the javadoc.You don’t need another servlet for this. JSF has already the
FacesServletas the sole request/response controller.