Chapter 1 Tutorials
Chapter 1 Tutorials
Poem
-
Open a text editor, like Notepad or vi.
-
Add the standard HTML tags: html, head, title, body.
-
Add the tags for validating the page: DOCTYPE, meta for content-type.
-
Add a poem in the body of the page; have at least 4 lines in the poem.
-
Save the file with the .html extension.
-
Open a web browser.
-
From the File menu, open the file you just saved.
-
You will notice that there is only one line of text that contains all the
lines of the poem.
-
Resize the browser until you see the line of the poem wrap to the next line.
-
This demonstrates how word wrap works.
-
Re-edit the poem file.
-
Add many spaces between some of the words.
-
Add many blank lines between two of the lines.
-
In the browser, reload the file.
-
All the text will be on one line.
-
You will only see one space between all the words.
-
This demonstrates how browsers compress all white space into a single space.
-
Re-edit the poem file.
-
Add a p tag at the start of the first line (this is required in order for
the page to contain valid HTML).
-
Add the br tag at the start of the second line.
-
Add the p tag at the start of the third line.
-
In the browser, reload the file.
-
You will see that the second line is directly below the first line.
-
You will see that the third line has at least one blank line between it and
the second line.
-
This demonstrates that new line characters must be added to the file with
mark up.
-
Go to w3c.org and validate that the page contains valid HTML.
-
You may ignore the warning that the form tag is missing the action attribute.
This will be explained in Chapter 2.
Simple Form
-
Open a text editor, like Notepad or vi.
-
Add the standard HTML tags: html, head, title, body.
-
Add the tags for validating the page: DOCTYPE, meta for content-type.
-
Add a form to the body of the page.
-
Add a paragraph of text that explains that the page is for entering data.
-
Add an text input element and a submit button in the form.
-
Open the file in a browser.
-
Enter some text in the text element.
-
Click the submit button.
-
Notice that the form data has been added to the end of the URL in the location
box of the browser.
-
Download and install
NetBeans.
You do not need GlassFish.
-
Choose a package that includes
Tomcat . I suggest that you download the one labeled
Java, it contains Tomcat.
-
We will be using Tomcat for this course.
-
On the first page of the NetBeans installation wizard, there is an option to customize the installation. Open the customization window.
-
On the page where you see Glassfish, be sure to install Tomcat as well. You may deselect GlassFish, you only need Tomcat.
-
Create a new web application, named
Tutorials .
-
In the Project tab, open the
Web Pages folder.
-
Create a new folder named
ch1 .
-
Create a subfolder of
ch1 named OnePage .
-
Create a new JSP named
First.jsp .
-
Do not use the JSP template that comes with NetBeans.
-
Right-click the
OnePage folder.
-
Select
New
-
Select
Other
-
Select
Empty File .
-
From now on, this option will be available when you select
New .
-
Copy the contents of the
SimpleForm.html into the First.jsp
file.
-
Add an EL statement that echoes the value of the contents of the text box.
-
You will see that the
index.jsp file already exists in the
Web Pages folder.
-
This is the welcome page for the application.
-
Modify the page by adding a hypertext link to the
First.jsp
file.
-
Run the project.
-
The
index.jsp page will appear in the browser.
-
Click the link for the first JSP.
-
Enter some text in the text element.
-
Click the submit button.
-
Notice that the text that was entered has been echoed in the page.
-
Notice that the form data is in the query string.
-
Validate that the
index.jsp and First.jsp files
contain valid HTML.
-
Create a new JSP named
FormInitialized.jsp .
-
Do not use the JSP template that comes with NetBeans.
-
Right-click the
OnePage folder.
-
Select
New
-
Select
Other
-
Select
Empty File .
-
From now on, this option will be available when you select
New .
-
Copy the contents of the
First.jsp file into the FormInitialized.jsp file.
-
Set the initial value of the text element to the corresponding value in the
query string. Use EL.
-
You will see that the
index.jsp file already exists in the
Web Pages folder.
-
This is the welcome page for the application.
-
Modify the page by adding a hypertext link to the
FormInitialized.jsp
file.
-
Run the project again.
-
Enter some text.
-
Click the submit button.
-
Notice that the text that was entered remains visible in the text element.
-
Validate that the
index.jsp and FormInitialized.jsp files
contain valid HTML.
|