To implement a simple jsp application
Exercise 1: Build and run HelloWorld JSP Application
- Download the sample code.
- Open hello1 NetBeans project.
- Select File->Open Project (Ctrl+Shift+O). The Open Project dialog box appears.
- Browse down to <LAB_UNZIPPED_DIRECTORY>/jspbasics/samples directory.
- Select hello1.
- Click Open Project Folder. The hello1 project node appears under Projects tab window.
- Build (F11) and run (F6) hello1 project.
- Right-click hello1 project and select Run Project.
- Browser gets displayed. Type your name in the input form field and click Submit button.
- Double click index.jps under hello1->Web Pages to open in the source editor.
- Modify the code such that it asks you a question.
- Modify response.jsp under hello1->Web Pages such that it fetches the information sent from the client and displays on the screen
Exercise 2: Write an application that fetches the HTTP Headers sent by the browser
- Write a jsp page or modify the sample code such that it fetches the following headers from the client's browser and displays them in the form of an .html page.
- HTTP Method
- Request URL
- Client's IP Address
- Content type supported by the browser
- List of all headers sent by the browser
Exercise 3: Add customized error pages to the web application
- Add a jsp page named myErrorPage to hello1->Web Pages.
- Right click WebPages and select New->JSP.
- Under New JSP File dialog box, for JSP File Name: field, type in myErrorPage.
- Mention that the file is to be created in the folder error .
- Click Finish.
- Modify the default page to display your error page.
- Note the directiive <%@ page isErrorPage="true" %>
<%@ page isErrorPage="true" %>
<h1> This is my own error page and the exception <%= exception.getMessage() %> tells me you
made a wrong choice.
- Add the directive <%@ page errorPage="error/myErrorPage.jsp" %> at the top of the page which you want to handle the error.
- In case of any exception thrown while your jsp page is executed, the container will execute the error page (if specified).
Exercise 4: Write an application that accesses the MySQL database server
- Write a JSP page or modify the sample code such that it fetches all the country names along with their population from the MySQL database server (as done in the previous lab) and lists them in a table within an .html page.
Exercise 5: Implement an application that utilizes session tracking
- Modify exersice 4 in such a way that the user has to login to access the list of all countries.
- Create a login jsp page that asks the username for his/her password.
- Store that information in the session object.
- Direct the user to the jsp page that lists the countries.
- If the user is logged in (i.e. the session objects maintain the correct password) then list the countries.
- Otherwise, redirect the user to the error page.
Instructions for submitting your work
- You are required to demonstrate your implementation during the lab.
- Create an archive (.zip) of your project folder and submit it online.
Last updated: 3rd December, 2007