Java Reference
In-Depth Information
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
try {
// Obtain value of Catalog Id field to ve validated.
String catalogId = request.getParameter("catalogId");
InitialContext context = new InitialContext();
SessionEJBFaçade beanRemote = (SessionEJBFaçade) context.
lookup(SessionEJBFaçadeBean.RemoteJNDIName);
Catalog catalog = beanRemote.validate(catalogId);
// set headers before accessing the Writer
response.setContentType("text/xml");
response.setHeader("Cache-Control", "no-cache");
PrintWriter out = response.getWriter();
// then write the response
// If Catalog is null set valid element to true
if (catalog != null) {
out.println("<catalog>" + "<valid>false</valid>" +
"<journal>" + catalog.getJournal() + "</journal>" +
"<publisher>" + catalog.getPublisher() + "</publisher>" +
"<edition>" + catalog.getEdition() + "</edition>" +
"<title>" + catalog.getTitle() + "</title>" + "<author>" +
catalog.getAuthor() + "</author>" + "</catalog>");
} else {
out.println("<valid>true</valid>");
}
} catch (javax.naming.NamingException e) {
System.err.println(e.getMessage());
}
}
public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
try {
// Obtain Connection
InitialContext context = new InitialContext();
SessionEJBFaçade beanRemote = (SessionEJBFaçade) context.
lookup(SessionEJBFaçadeBean.RemoteJNDIName);
String catalogId = request.getParameter("catalogId");
String journal = request.getParameter("journal");
String publisher = request.getParameter("publisher");
String edition = request.getParameter("edition");
String title = request.getParameter("title");
String author = request.getParameter("author");
beanRemote.persist(catalogId, journal, publisher, edition,
title,author);
response.sendRedirect("catalog.jsp");
} catch (javax.naming.NamingException e) {
 
Search WWH ::




Custom Search