390 IBM WebSphere Host Publisher Version 3.5
14.4.3 Step 3: Develop servlets in VisualAge for Java
Now we will create a new package named hp_servlets and the two sample
servlets InputRequest and HostResponse (see Figure 14-6).
Figure 14-6 hp_servlets package with two servlets
In the following paragraphs, we will give some basic information on how to write
the two servlets. For more detailed information on how to write servlets, you can
read Servlet and JSP Programming with IBM WebSphere Studio and VisualAge
for Java, SG24-5755.
To write the servlets shown in this scenario, you should be familiar with the
get
and
set methods created in the Integration Object. In this case, we should do the
following in the HostResponse Servlets performTask method:
1. Instantiate the Integration Object Hobj01.
2. Invoke the Integration Objects setAccountVar method passing the account
typed in the InputRequest Servlet.
3. Perform the inquiry transaction to the CICS host application by invoking the
doHPTransaction method.
Chapter 14. Integration Objects and VisualAge for Java 391
4. Send the information received from the host back to the browser as HTML
code.
See Figure 14-7 on page 392 and Figure 14-8 on page 393 for details on the
Java code used in both servlets.
392 IBM WebSphere Host Publisher Version 3.5
Figure 14-7 InputRequest sample servlet
package hp_servlets;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class InputRequest extends javax.servlet.http.HttpServlet {
public void doGet(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response) throws
javax.servlet.ServletException, java.io.IOException {
performTask(request, response);
}
public void performTask(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response) {
try
{
// sending input form to browser
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<HTML><TITLE>IBM Host Publisher 3.5 Input Request
Servlet</TITLE><BODY>");
out.println("<H2>Please provide the following Information</H2><HR>");
out.println("<FORM METHOD=\"POST\" ACTION =\"HostResponse\">");
out.println("<P>Please Type Account Number: ");
out.println("<INPUT TYPE=\"TEXT\" NAME=\"account\"></P><BR>");
out.println("<INPUT TYPE=\"SUBMIT\" VALUE=\"SUBMIT\">");
out.println("</FORM>");
out.println("</BODY><HTML>");
out.close();
}
catch(Throwable theException)
{
// uncomment the following line when unexpected exceptions
// are occuring to aid in debugging the problem.
//theException.printStackTrace();
}
}
}
Chapter 14. Integration Objects and VisualAge for Java 393
Figure 14-8 HostResponse sample servlet
package hp_servlets;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import IntegrationObject.*;
public class HostResponse extends javax.servlet.http.HttpServlet {
public void doPost(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response) throws
javax.servlet.ServletException, java.io.IOException {
performTask(request, response);
}
public void performTask(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response) {
try {
// Instantiate Integration Object
Hobj01 io = new Hobj01();
// set account number
io.setAccountVar(request.getParameter("account"));
// execute search
io.doHPTransaction (request, response);
// send response back to browser
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<HTML><TITLE>IBM Host Publisher 3.5 Response
Servlet</TITLE><BODY>");
out.println("<H1>IBM HP 3.5 Response Servlet</H1><HR>");
out.println("<H2>ACCOUNT INFORMATION</H2>");
out.println("<H4>Account No. " + io.getAccountOut() +"</H4>");
out.println("<H4>First Name: " + io.getFirstnameOut() +"</H4>");
out.println("<H4>Last Name: " +io.getSurnameOut() +"</H4>");
out.println("<H4>Address: " + io.getAddressOut() +"</H4>");
out.println("</BODY><HTML>");
out.close();
}
catch(Throwable theException)
{
// uncomment the following line when unexpected exceptions
// are occuring to aid in debugging the problem.
//theException.printStackTrace();
}
}
}

Get A Comprehensive Guide to IBM WebSphere Host Publisher Version 3.5 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.