Module Four: Java in WebSphere

tieplantlimabeansSoftware and s/w Development

Oct 28, 2013 (3 years and 5 months ago)

50 views

Objective:
The purpose of this lab is to create a simple JavaServer Page (JSP) with the same functions as the
servlet you previously created.
You create the JSP in WordPad or Notepad and test it in VisualAge for Java before you move it
over to OS/390 and run it.
Step 1.
Create HelloJSP.jsp in Wordpad/Notepad as follows:
 What you need for HelloJSP.jsp is scriptlets.
 Skeleton of the HelloJSP.jsp:
<html>
<head>
<title>Hello JSP Example</title>
</head>
<body>
<%
Scriptlet
%>
</body>
</html>
 What you need for the scriptlet of the HelloJSP.jsp:
1.Initialize name:
String name = null;
2.Get the input name from the Web Browser:
name = request.getParameter("name");
3.Format output as html:
Condition 1: if you get the name from the url ((if name != null)):
out.println("<html><head><title>Hello " + name +"</title></head><body>");
out.println("<h2><font color=darkblue> " + name + ", welcome to the IBM
Workshop</font></h2>");
out.println("</body></html>");
Condition 2: else, ask for the name:
out.println("<html><head><title>Hello</title></head><body>");
out.println("<h2><font color=darkblue> May I have your Name?</font> </h2>");
out.println("<form method=get action=\"/HelloJSP.jsp\">");
out.println("<input type=text name=\"name\"><p>");
out.println("<input type=submit value=\"Submit\">");
out.println("</form></body></html>");
out.println("</form></body></html>");
Step 2.
Save HelloJSP.jsp to:
<drive letter>:\IBMVJava\IDE\project_resources\IBM WebSphere
Test Environment\hosts\default_host\default_app\web
Module Four: Java in WebSphere
Lab Two: Create and Deploy a simple JavaServer Page
© IBM Corporation, 2000 Page 1 of 5
D:\workshops\ITS65-Brazil\Wordpro labs\ITS65_module 4 Hello JSP
Step 3.
Launch IBM WebSphere Test Environment:
Select Workspace -> Tools -> Launch WebSphere Test Environment
Launch JSP Execution Monitor:
Select Workspace -> Tools -> JSP Execution Monitor
 If you do not have this feature yet in your Workspace Tools, then you
need to install it:
Select File -> Quick Start -> Features -> Add Features
Select IBM JSP Execution Monitor
Test the HelloJSP.jsp from your Web browser:
Module Four: Java in WebSphere
Lab Two: Create and Deploy a simple JavaServer Page
© IBM Corporation, 2000 Page 2 of 5
D:\workshops\ITS65-Brazil\Wordpro labs\ITS65_module 4 Hello JSP
Http://localhost:8080/HelloJSP.jsp
The “JSP Execution Monitor” window will appear now (this may take a
while....), as shown in the next window:
To run the servlet, click the Run icon in the JSP Execution Monitor; to step
line-by-line through the JSP, click the Step icon.
If you have finished testing, close the JSP Execution Monitor and the
WebSphere Test Environment.
Step 4.
Move HelloJSP.jsp to the <drive letter>:\javalabs directory of your
workstation and ftp HelloJSP.jsp to the pub directory (refer to your
worksheet) of your personal Web server.
Step 5.
Start your Web browser.
Enter your Web server’s address, port number and HelloJSP.jsp, as follows:
http://[TCP/IP address]:[Port number]/HelloJSP.jsp
As you have learned in the lecture, WebSphere Application Server will
dynamically create a servlet and compile it.
Module Four: Java in WebSphere
Lab Two: Create and Deploy a simple JavaServer Page
© IBM Corporation, 2000 Page 3 of 5
D:\workshops\ITS65-Brazil\Wordpro labs\ITS65_module 4 Hello JSP
The created servlet source and class will be placed in a directory called
/was/<your Web server>/AppServer/servlets/pagecompile/
Module Four: Java in WebSphere
Lab Two: Create and Deploy a simple JavaServer Page
© IBM Corporation, 2000 Page 4 of 5
D:\workshops\ITS65-Brazil\Wordpro labs\ITS65_module 4 Hello JSP
HelloJSP.jsp Source Code:
<html>
<head>
<title>Hello JSP Example</title>
</head>
<body>
<%
String name = null;
name = request.getParameter("name");
if (name != null)
{
out.println("<html><head><title>Hello " + name
+"</title></head><body>");
out.println("<h2><font color=darkblue> " + name + ", welcome to the IBM
Workshop </font> </h2>");
out.println("</body></html>");
}
else
{
out.println("<html><head><title>Hello</title></head><body>");
out.println("<h2><font color=darkblue> May I have your Name? </font>
</h2>");
out.println("<form method=get action=\"/HelloJSP.jsp\">");
out.println("<input type=text name=\"name\"><p>");
out.println("<input type=submit value=\"Submit\">");
out.println("</form></body></html>");
}
%>
</body>
</html>
Module Four: Java in WebSphere
Lab Two: Create and Deploy a simple JavaServer Page
© IBM Corporation, 2000 Page 5 of 5
D:\workshops\ITS65-Brazil\Wordpro labs\ITS65_module 4 Hello JSP