Java程序辅导

C C++ Java Python Processing编程在线培训 程序编写 软件开发 视频讲解

客服在线QQ:2653320439 微信:ittutor Email:itutor@qq.com
wx: cjtutor
QQ: 2653320439
CS381 - Lab Session 4 
 
 
 
A. Setting up Tomcat. 
1. Open a browser and go to http://www.ee.surrey.ac.uk/SCS/tomcat/ 
2. Follow the instructions given on the page and make sure that Tomcat is up and 
running by testing the given servlet and JSP pages. 
3. Make a new web application area by creating a folder called “webtech” under 
the “tomcat/webapps” directory. 
4. Create a “WEB-INF” folder under “tomcat/webapps/webtech” directory, and a 
“classes” and a “lib” folder under “tomcat/webapps/webtech/WEB-INF” 
directory (make sure it looks the same like the “ROOT” directory structure). 
5. Stop tomcat (~/tomcat/bin/tomstop) and then restart it (~/tomcat/bin/tomstart). 
 
 
 
B. Publishing an HTML page on the Web. 
1. Using “nedit” or “notepad” or your tool of choice, create a new text file, and 
add the required HTML elements (you could use the HTML file created in one 
of the previous labs). 
2. Add a message on the page (e.g. “Hello world”). 
3. Save the file as index.html within the “tomcat/webapps/webtech” directory. 
4. Open the page in your browser (e.g. 
http://workstation01.ee.surrey.ac.uk:49999/webtech) 
 
 
 
C. Creating a simple JSP. 
1. Using “nedit” or “notepad” or your tool of choice, create a new text file, and 
add the required HTML elements (you could use the HTML file created in one 
of the previous labs). 
2. Add a JSP element for the date, i.e. <%= new java.util.Date()%> 
3. Save the file as date.jsp within the “tomcat/webapps/webtech” directory 
4. Stop and re-start tomcat 
5. Open the page in your browser (e.g. 
http://workstation01.ee.surrey.ac.uk:49999/webtech/date.jsp) 
6. Create a file header.jsp (cut and paste HTML elements of date.jsp up to the 
JSP element for the date) and reference header.jsp from date.jsp (e.g. <%@ 
include file='./header.jsp'% >). Create a file footer.jsp (cut and paste HTML 
elements of date.jsp after the JSP element for the date) and reference footer.jsp 
from date.jsp. Save all three files in the same directory as date.jsp 
7. Open the page in your browser (e.g. 
http://workstation01.ee.surrey.ac.uk:49999/webtech/date.jsp) 
 
 
 
 
 
 
D. Creating a simple JavaBean. 
1. Using “nedit” or “notepad” or your tool of choice, create a new text file for a 
Bean, e.g. you could use the following and name it DateFormatBean.java 
 
package webtech; 
 
import java.text.DateFormat; 
import java.text.SimpleDateFormat; 
import java.util.Date; 
 
public class DateFormatBean 
{ 
 
    private DateFormat dateFormat; 
    private Date date; 
 
    public DateFormatBean() 
    { 
        dateFormat = DateFormat.getDateInstance(); 
        date = new Date(); 
    } 
 
    public String getDate() 
    { 
        return dateFormat.format(date); 
    } 
} 
2. Save the file as DateFormatBean.java within the appropriate directory,  
      (i.e. tomcat/webapps/webtech/WEB-INF/classes/webtech) 
3. Compile the Bean you just created (i.e. cd into 
tomcat/webapps/webtech/WEB-INF/classes and then run javac 
webtech/DateFormatBean.java 
4. Modify the file date.jsp that you created for Exercise D by: 
a. removing the existing JSP element for the date 
b. adding a JSP element  
5. Save the file as dateBean.jsp within the appropriate directory,  
      (i.e. tomcat/webapps/webtech) 
6. Stop and re-start tomcat 
7. Open the page in your browser  
      (i.e. http://workstation01.ee.surrey.ac.uk:49999/webtech/dateBean.jsp)