corner index.html
ContactTelephone & Email CreditsCaptions & Contributors Workshop Everything else RésuméDavid Segall Homewelcome

Back to Workshop Selecting a Java IDE Problem playing DTMF tones (source code) Installing Cloudscape/Derby with Tomcat and ODBC Free, heavy duty, databases Accessing GET data from JSF and Studio Creator/NetBeans VWP A Web Presence at Minimum Cost RAD Web Development Tools HTML/CSS Multi column layout

bottom corner

Accessing GET data from Java Server Faces

The approved method of communicating with a Java Server Faces web page is by using POST data. This is more secure and, for most purposes, more flexible than using the GET method to transfer data. However, POST data cannot be used to bookmark a page whereas GET data is included with the URL and so can be recorded and resent at some later time.

As an example, only GET data can be used for the typical email that contains "Click this link to confirm your membership". The URL would be in the form html://www.example.com/confirm.jsp?MemberNum=123456. The JSF page confirm.jsp has to extract the member's number from the URL so that it can record the new member as confirmed. JSF expects data of this kind to be in a backing bean so the problem becomes how to extract the GET data and set the member number in the bean.

In order to access the GET data we need to read it from the FacesContext object. Mark Chung's blog suggests using a Filter. A Filter is a general way of pre-processing any Java Server Page and there is in an excellent account of Filters in Marty Hall's More Servlets and JavaServer Pages. The relevant chapter, Servlet and JSP Filters, is available for download.

If you are using Java Studio Creator or the Visual Web Pack in NetBeans there is a much simpler way of obtaining the GET data because they generate code which can access the context immediately before a page is rendered. The following code can be inserted in the prerender method of the servlet.

Object paramObject = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("MemberNum");
if (paramObject != null) {
getRequestBean1().setMemberNum(paramObject.toString());
} else {
getRequestBean1().setMemberNum(null);
}

bottom corner