Afrikaans
Akan
Albanian
Amharic
Arabic
Armenian
Azerbaijani
Basque
Belarusian
Bemba
Bengali
Bihari
Bosnian
Breton
Bulgarian
Cambodian
Catalan
Cebuano
Cherokee
Chichewa
Chinese (Simplified)
Chinese (Traditional)
Corsican
Croatian
Czech
Danish
Dutch
English
Esperanto
Estonian
Ewe
Faroese
Filipino
Finnish
French
Frisian
Ga
Galician
Georgian
German
Greek
Guarani
Gujarati
Haitian Creole
Hausa
Hawaiian
Hebrew
Hindi
Hmong
Hungarian
Icelandic
Igbo
Indonesian
Interlingua
Irish
Italian
Japanese
Javanese
Kannada
Kazakh
Kinyarwanda
Kirundi
Kongo
Korean
Krio (Sierra Leone)
Kurdish
Kurdish (Soranรฎ)
Kyrgyz
Laothian
Latin
Latvian
Lingala
Lithuanian
Lozi
Luganda
Luo
Luxembourgish
Macedonian
Malagasy
Malay
Malayalam
Maltese
Maori
Marathi
Mauritian Creole
Moldavian
Mongolian
Myanmar (Burmese)
Montenegrin
Nepali
Nigerian Pidgin
Northern Sotho
Norwegian
Norwegian (Nynorsk)
Occitan
Oriya
Oromo
Pashto
Persian
Polish
Portuguese (Brazil)
Portuguese (Portugal)
Punjabi
Quechua
Romanian
Romansh
Runyakitara
Russian
Samoan
Scots Gaelic
Serbian
Serbo-Croatian
Sesotho
Setswana
Seychellois Creole
Shona
Sindhi
Sinhalese
Slovak
Slovenian
Somali
Spanish
Spanish (Latin American)
Sundanese
Swahili
Swedish
Tajik
Tamil
Tatar
Telugu
Thai
Tigrinya
Tonga
Tshiluba
Tumbuka
Turkish
Turkmen
Twi
Uighur
Ukrainian
Urdu
Uzbek
Welsh
Wolof
Xhosa
Yiddish
Yoruba
Zulu
In this section, you will learn how to create home page for our Bookstore website
home page is the default page which the customers see when they are visiting the website
As you know, our web application is divided into two parts: the front-end and the back-end
The front-end is for the users or customers
and the back-end is for company's staffs and managers
The homepage we are going to create is the home page of the front-end
so it is called website's home page
And the home page for the back-end is called admin's home page which we create in the next section
Here's our task list in this section:
create website's homepage
we create home page index.jsp and then we create a home page servlet
and we create the header and create the footer
And this is the design our website's home page
it also describes the structure of every web page in our web application
that includes the header, the main content, and footer
The header and footer are common for all pages, but the main content varies depending on every particular page
You see, in the website's home page...
the main content displays new books, best-selling books and most favored books
The header displays company's logo,
a search bar, user's menu and book categories menu
The footer displays copyright information with common pages like
about us, contact us, privacy policy, shipping and delivery
Now, let's create the home page - index.jsp page
okay, so expand the WebContent folder here...
and because we are going to create the home page for the front-end
so we need to create a JSP page in the frontend directory you see here
Right-click -> New > JSP File
and name it as index.jsp
click Finish
Okay, you can see some generated HTML code here...
and we change the title for the home page is:
company name is Evergreen Books
okay
Let's see...
Evergreen Books is the company name
Evergreen Books
Online Bookstore
okay
and we can...
use the heading tag to...
...display a test message, okay.
Welcome to
Welcome to Books Store
okay
Now, let's test our web application
so in the Servers view, you can see our Bookstore website project is shown here...
under the Tomcat 9.0 server
okay
Now right-click on the server and Start
Okay, the server is up running
Now we can open an Internal Web Browser...
...inside Eclipse to test our web application
type web
internal web browser
Open
And now we can type the URL to assess our web application
http://localhost
port number is 8080
and...
our web application name or context root is BookStoreWebsite
Enter
you see
the message 'Welcome to Evergreen Book Store!'
you see...
...the message of this index.jsp we created before, so...
because our home page for the front-end is under the frontend directory
so we need to specify the frontend
sorry
/frontend/index.jsp here
and you see
the message is 'Welcome to Book Store ' - that's exactly what we have typed in this index.jsp
Welcome to Book Store
We need to delete this index.jsp file
under the WebContent directory
Delete
OK
You can see that is not convenient for customers to visit our website by typing this URL
you want that the customer can assess the website like this
just type the domain name or the website name like this
you see
We have 404 error now because we have deleted the index.jsp under the web application's root directory
no problem
as we will create a home page servlet to redirect the customers to our front-end's home page
our second task is to create the home page servlet that is responsible to redirect the users, the visitors to the index.jsp page
which is inside the frontend directory here...
the reason that we need to put our home page...
under a separate directory because we want to separate files for two parts: admin and front-end
back-end and front-end
you see
to create our home page servlet...
this servlet should be in this Java package:
com.bookstore.controller.frontend
Right click > New
Servlet
okay, and enter the servlet as...
HomePageServlet
okay
No, HomeServlet for short
okay
click Next
and here, the URL mapping...
we edit URL mapping
empty, okay.
just empty
this is forward slash (/)
okay, so click Finish
okay, and you can see the servlet class is generated here
okay let's see...
delete the doPost() method because we implement only the doGet() method
okay
delete all the comments
not necessary
okay
you can see...
this class is annotated with the @WebServlet annotation to indicate that this is a Java Servlet
and the string as the argument for this annotation is the URL pattern
for this servlet, we use the...
we use the empty string to indicate that the servlet will handle the request...
this servlet will handle user's requests to the website's home page
In other words, this servlet - HomeServlet - with the URL mapping an empty string...
will handle...
requests come to the website's home page like this
okay
and in the..
Now let's try to save the servlet
and you can see a server is automatically restarted
If not, we restart the server
Restart
Now...
Open Internal web browser
and...
hit Enter
and you see
this is the message from the doGet() method of the servlet
so that means this HomeServlet is responsible to handle requests to the website's context root
this is the...
you see
Now we want to....
redirect the visitors to our index.jsp page
inside the frontend directory
okay
okay, to do so...
we need to obtain a RequestDispatcher from the request
request.getRequestDispatcher()
and the page we want to redirect is the frontend/index.jsp
and assign the returned object as a RequestDispatcher object
RequestDispatcher object
dispatcher
okay
page
and...
dispatcher.forward(request, response)
this can be the renamed...
this is the homepage
okay
okay, you see the server is automatically restarted
the message: Reloading context
okay
Now, open the internal web browser and refresh the page
hit Enter
and you see now:
the message 'Welcome to Books Store'
this is from this index.jsp page
Now let's try to add something
okay
Have a great day
okay
Save this file
and...
Refresh the website
you see
the new message 'Have a great day!' is displayed
the reason we need to have a separate Java class
Java servlet
to handle requests coming to the website's homepage is because ...
...we want to separate the controller and the model from the view
in MVC model
and as you can see...
in the home page...
we need to connect to the database to get information about the book categories
new books, best-selling books and most favored books
so...
the code to...
the code to do...
to retrieve this information...
...is in the servlet class
and the view - the JSP page is...
only to display the information
that's why we need to have a separate Java servlet
to handle requests to the home page
okay
let's edit the index.jsp page
using a tag
okay
align = "center"
This is header
heading 1 tag
this is the header
the header can include logo, search bar, menu
and this is the next part is: This is main content
okay
New books
Best-selling books
and the last section is the footer
This is footer
that includes copyright
about, contacts
heading 3, heading 4
okay
that's similar to the structure of the home page: header, main content and footer
Now, refresh the web page
you can see
this is header, this is content and this is footer
in the main content we have three sections: new books, best-selling books and most favored books
New books
Best-selling Books
and Most favored Books
Now refresh the web page
in the internal web browser
you see
so this is the structure of our home page:
the header, main content and footer
Suppose that we need to have a login page that allows the customer to log in to the website
so I create another JSP page here
login.jsp
click Finish
the login page has similar structure to the home page
except for the main content that displays a login form
so I copy this HTML code from the index.jsp to this login.jsp page
and change the page title to Login
ok
you can see
the header and the footer are the same
the main content is different
for example, we... here in the login page
'Please login'
okay
Now, let's try to assess this login page from the browser
we need to specify the frontend
and login.jsp
you see
this page also has header, footer and only the main content is different
for example, we can create a form here
let's display the input fields for username passwords
type
input type="text"
okay
size is 10
user..
break newline
password
is: input type="password"
size is also 10
okay
and...
login button
input type="submit"
value="login"
okay
let's refresh this page
you see
a very simple login page
okay
you can see login page page and the index - the home page has something in common
it is the header and the footer
so what if we have many JSP files here?
later in the project development we will add more and more JSP files here
so...
we will have duplicate code here - in the header and footer
so...
that's why we need to...
extract the common
the common information in the header and footer into separate JSP files called the header and the footer
so let's create the header JSP page here
name it as header.jsp
click Finish
and create footer
footer.jsp
and the header contains the common code
for example
it is the logo
logo, search and menu
so we copy this here
sorry, I copy from the home page first
okay
copy here and paste into the header
okay
save
okay
and copy the footer section into the footer.jsp page
JSP
okay
you see
footer
header
okay
and in...
JSP page, we can use the JSP directive to include the content of the header and footer pages into the home page
here we replace by the JSP directive
jsp:directive.include
and...
the attribute file is the...
the attribute file is the header.jsp
header.jsp
we do the same for the footer
replace this code with the include directive JSP
jsp:directive.include file="footer.jsp"
okay
and now let's refresh the home page
you see:
header, main content and footer
Now, let's do the same for the login page
copy this header
and footer
Save
Now, refresh the login page
frontend
login.jsp
you see
the user interface remains unchanged but in the code we restructure to have the common code stored in header and footer page
you see
Now, let's update the header page
update the header page with logo,
search box and some user's menus: Sign in, Register and Cart
I have the logo here
you see: Evergreen Bookstore
and...
you see, in the project we have the images directory here
and I copy the logo image to that directory
copy
paste
okay
this is the header.jsp page
there's a tag to display the logo
using the image tag
image
source src is the path to the logo image
you see, in our project, it is under the images directory
images/BookstoreLogo.png
this path is relative to the JSP files
you see
the header.jsp page is here, and...
the BookstoreLogo image is here
okay
Let's refresh our website
Enter
you see: the logo appears very nice, right?
Next, we add a div section to...
display the search box
search box here
input type="text"
name is keyword
size is about 50
okay
refresh the page
you see, there's a small text box here
this is a search box
that allows the user to type a keyword and search for books in the website
and...
after the text box we have the Search button
search button: you can see here
okay
input type="button"
value is the caption of the button: Search
Now, refresh the web page - home page
and you see: the Search button appears here
And now for the user's menu we have Sign in, Register and Cart
we put the user's menu items here
Sign in
Register and Cart
they are hyperlinks so we use the anchor tags
anchor tag or
reference (href)
Sign in
for example
the URL is relative: login
okay
Save the file, refresh the home page
and you see, the Sign in hyperlink here
click here
it doesn't work because we haven't implemented the login function yet
okay
similarly we do the same for Register and Cart
the URL for Register is register
okay
here is, for example: view_cart
okay
and...
Save the file and refresh the homepage
you can see, we have three user's menu items here:
Sign in, Register and Cart
Now, let's add a...
this character
okay
Refresh
we need to have some spaces between the search bar and the menu items
we use the HTML escape character space ( ) here
Refresh
you see
For the menu that displays the book categories
we will implement later because it requires to connect to the database and retrieve the categories from the database
okay
You can open a web browser - Chrome - and access our web application to see how it looks in Chrome
okay
you see
that looks... pretty nice, right?
Next, let's update the footer
the footer.jsp here
and...
according to the design we have the copyright statement
copyright
by Evergreen books company limited
okay
copyright 2018
When I design this user interface, it was 2017, but now it is 2018
okay
by Evergreen Books Company Limited
okay
and under the copyright statement we have some...
menu items: about us, contact us, privacy policy, shipping and delivery
About Us
okay
Save the file and refresh our web page
you see
the copyright statement here
About Us
okay
URL is about
and the next menu item is...
Contact Us
Contact Us
Contact
okay
the next is Privacy Policy
Privacy Policy
URL is policy
and...
the last menu item is Shipping and Delivery
Shipping and Delivery
shipping
okay
Now let's refresh the home page
and you see, we have the menu items in the footer appears here. very good, right?
you can see: New Books, Best-Selling Books, Most favored Books
is the main content of the home page
is the index.jsp page here
let's add some line breaks here
to see the main content more clearly...
from the header and footer
okay
and refresh the home page
you see
Refresh the home page in Chrome browser
you see
header here, footer here and this is the main content
and let's try to access the login page - login.jsp, and you can see..
the image doesn't get display
No problem, we will fix this later
but you see: it also has the footer and...
footer and header
okay
so that's...
create the website's home page with the header and footer
very simple, right?
and along the course, we will develop and complete the header the footer and the home page
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.