Java Reference
In-Depth Information
In the Servlet Parameters window, servlet parameters may be specified. Click on
Finish . We shall be packaging the servlet class in a WAR file along with the JSP UIs
for the Ajax. In the web.xml, the EJB3ClientServlet and the url pattern to invoke
the servlet get specified. The web.xml is listed below:
<?xml version = '1.0' encoding = 'windows-1252'?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.
sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5" xmlns="http://java.sun.com/xml/ns/javaee">
<servlet>
<servlet-name>EJB3ClientServlet</servlet-name>
<servlet-class>view.EJB3ClientServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>EJB3ClientServlet</servlet-name>
<url-pattern>/ejb3clientservlet</url-pattern>
</servlet-mapping>
</web-app>
The Servlet class
The Ajax request is sent from the input form to the doGet() method of the servlet.
In the doGet() method, create an InitialContext object:
InitialContext context = new InitialContext();
Lookup the remote business interface using the remote JNDI name:
SessionEJBFaƧade beanRemote = (SessionEJBFaƧade) context.
lookup(SessionEJBFaƧadeBean.RemoteJNDIName);
Retrieve the catalog id input field value and invoke the validate() method of the
session bean:
String catalogId =request.getParameter("catalogId");
Catalog catalog = beanRemote.validate(catalogId);
The servlet sends a response to the browser as an XML string; therefore, set the
content type of the HttpServletResponse to text/xml , and the cache-control
header to no-cache :
response.setContentType("text/xml");
response.setHeader("Cache-Control", "no-cache");
 
Search WWH ::




Custom Search