In this Java web application tutorial I'll show you how to create dynamic websites using the core technologies of Java web programming. If you want to create your own interactive websites, if you know some Java and you want to take your skills to the next level, or if you want hot skills for the job marketplace, this Java web application tutorial course is for you.
In this Java web application tutorial course you'll learn how to:
I'll show you how to take your basic Java knowledge and use it to create websites using the same technologies (servlets, JSPs and JSTL) that everyone from self-employed web developers to huge corporations use to create modern interactive web sites.
About the course, and why you should learn web programming with Java.
In this tutorial we'll look at what software you need to install to start developing Java-based websites. All the software you need is free; we'll be using the industry-standard Eclipse IDE together with the highly popular Tomcat server. And of course, the JDK and JRE (Java Development Kit and Java Runtime Environment).
In this tutorial we'll create a "hello world" Java servlet. A servlet is a Java class that runs in an "application server" and sends web pages back to a browser when a user somewhere in the world clicks on a URL. Here we'll get started by creating a really simple servlet that creates the simplest possible web page.
In this tutorial we'll look at a better way out outputting HTML, rather than having to hardcode it in your servlet. JSPs are another of the core building blocks of Java web applications, allowing you to combine HTML and Java seamlessly.
In this tutorial we'll look at the web.xml file; a standard config file that enables us to, among other things, map urls to servlets and JSPs in our applications. We'll need to understand web.xml before we can move on to deploying our applications on the Internet. I'll also give you some tips that may help to ensure you will seldom have to look at web.xml, except when you want to customise your URLs.
In this tutorial we'll look at deploying your application to a Tomcat server using a .war file. Deploying Java web applications is surprisingly simple, provided you've got a working web.xml.
Cloudbees.com, which I originally recommended using to upload your servlet is being or has been decommissioned. There are lots of other options around though -- for example, try https://www.openshift.com, which lets you set up lots of kinds of app server projects -- Java Tomcat included.
In this tutorial we'll look at how you can deploy your application to the Internet, and without even paying a penny.
We've seen so far that you can use Java in your JSPs via scriptlet tags; but to really leverage Java (as well as to keep your JSPs reasonably simple) you'll want to import your own and other Java classes into JSPs. We'll see how to do that in this tutorial.
In this tutorial we'll look at the vital topic of how to retrieve parameters from the URL in JSPs and servlets.
In this tutorial we'll discover a slightly surprising but very important use of scriptlets; looping or conditionally including entire blocks of HTML.
In this tutorial we'll look at techniques for including files within other files, so that you can build your application up out of chunks of HTML contained in separate files. For instance, you can have a file containing header for all your pages which you can then include in all the pages on your website.
Note: I said in this tutorial that jsp:include causes a separate browser request --- but actually this isn't quite right; jsp:include causes a sort of simulated request, apparently --- not an actual request from the browser.
In this tutorial we'll look at various ways of getting a servlet or JSP page to display another page; a powerful technique that enables you to build fully-fledged Model-View-Controller applications, among many other things.
The declaration tag allows you to add methods and data members to the servlet that your JSP gets translated into, which is occasionally useful .... actually its main use is probably just that it makes it clearer where your Java actually ends up when you use Java scriptlets in JSPs.
In this tutorial we'll take a look at the types of tags that we've seen so far.
In this tutorial we'll look at the difference between Model 1 and Model 2 architecture; two important ways of structuring your web applications.
Some tips about using jar files containing external APIs in your web projects.
The servlet lifecycle is something you'll definitely get asked about if you go for a job interview or sit an exam. For that reason, we'll review it in this tutorial.
Beans are a mechanism for sharing data between JSPs and for maintaining state in your application. In this tutorial we look at a simple example of a bean, storing some information about the user.
The notion of "scope" is very important in web programming; we'll start to look at it in this tutorial, in the context of JSP beans.
This tutorial looks at how to set bean properties from parameters; either URL parameters or, as we'll see later on, parameters set by the user submitting a form.
Forms are, of course, a vital part of web programming, allowing you to gather information from your users or allowing them to log in to your website. Here we'll start looking at adding forms to your applications using the ideas we've seen so far, plus some HTML.
Posts are a type of HTTP request in which the data you submit doesn't appear in the URL, by-passing the data limit on URLs and making for much nicer URLs, among other things. Data from forms is usually submitted via post, not "get". We'll look at how easy it is to make your forms post data in this tutorial.
Beans are a great way to collect data from forms. We'll see how to do just that in this tutorial.
Beans are a handy place to put server-side validation code. If we add validation code to a bean, we can check if the information the user has entered in a form makes sense or not by filling in the bean and calling its validation method.
By bringing together some of the techniques we've seen so far, we can create a form that validates itself, allowing itself to be submitted to your servlet or confirmation page only when the user has entered valid input.
In this tutorial we'll take a look at a little web application that uses a strict MVC architecture, incorporating our bean validation code and validating the bean in the controller rather than the JSP.
The session object allows you to store objects and data that persist for the duration of the user's session, making it an indispensable tool for maintaining application state while your user is browsing your site.
How can you maintain session if the user disables cookies? In this tutorial we'll look at a form of URL rewriting that adds a session ID to your links, allowing session to be maintained.
Note: some argue that session IDs in URLs are a security risk; you may decide instead either to not use sessions or to allow your site to simply not work if the user disables cookies.
If you turn of cookies in your browser while following this tutorial, don't forget to turn them on again so you can continue following the Udemy course!
You can use the context object to store data that persists as long as your server is running, and is shared between all users.
If you have some parameters, for example user names and passwords, that you want to be configurable for your web application, one place to put them is web.xml. You can use the servlet context object to retrieve these parameters.
So far we've discussed scope in the context of JSPs, and we've seen various objects that exist at different scopes in servlets. Here we'll review the three servlet scoped objects that we've seen.
Cookies are both loved and loathed, but either way they're an essential part of the Internet. In this tutorial we'll look at how to get and set cookies in a servlet.
If you're serious about web programming, you'll definitely want to connect to a database at some point. Database connectivity can be achieved in servlets using the generic database Java API known as JDBC. In this tutorial we'll look at a simple way you can connect to a database using JDBC, that works in any kind of Java program.
If you're working on an industrial-strength web app, you'll definitely want to set up a JNDI data source, implementing connection pooling and connection timeouts and so preventing application crashes from using up your database connections. You'll probably also need to use JNDI if you're deploying your application to an application server that you don't personally control.
In this tutorial, as an example of doing a database query, we'll create a form that allows a user to log in to a website, only allowing the user in if the entered email address and password match those stored in the database.
In this tutorial we'll look at an example of inserting data into a database, creating an application that lets the user create an account in our demo web application.
You can send email from your servlet or other Java program, provided you've got access to a mail server (which you can get for free) and the Java Mail API.
In this tutorial we'll look at an example of sending an email using the mail API, together with an SMTP server.
Up till this point in the course we've covered just about everything you need to know to implement a web application; however, our code is getting messy and a lot of it is not exactly elegant. Fear not; in this tutorial we'll look at another standard technology that will allow us to greatly simply our code, making it more elegant and more maintainable.
How to access beans using JSTL, and a first look at EL (Expression Language)
You can fetch parameters in JSTL by using an "implicit object", the param object.
Just like Java, JSTL has an "if" statement, allowing you to dispense with using ifs in Java scriptlets in your JSPs.
The "if" tag in JSTL is pretty limited, not allowing any kind of else or else-if clause. For that you need the "choose" tag, which allows you to pick between multiple possibilities.
JSTL has an equivalent construct to the Java for loop in the form of the "foreach" loop. Here we'll take a look at foreach and some of its most useful attributes.
You can set objects as attributes on the request, session or web context object in your servlet and references them in your JSPs using a very simple EL syntax, which we'll look at here. Basically this enables you to passing Java objects to your JSP pages and references them in JSTL.
In this tutorial we'll look at some further (in addiction to param) predefined objects that you can use in EL, enabling you to do lots of useful stuff.
You can set a Java Map into one of the scoped objects and then access its values from JSTL. We'll look at how to do it here.
You can actually output stuff on your JSP page by using an EL expression directly on the page, outside of any JSTL tags. On the other hand, if you need your strings to be escaped, you need c:out. We'll take a closer look here.
You can use the JSTL forEach loop to iterate through the items in a Java List or any one of various collection types. We'll see how to do it here, and later on this is going to come in very handy when we look at dealing with the results of SQL queries in JSTL.
In this tutorial we'll look at how to take files created by a designer (or yourself) and turn them into a dynamic web project. Along the way we'll look at how to use graphics in a web application, and we'll see a really simple way to access the context root.
We've already seen two good ways to include content in other content; here we'll look at the JSTL way of doing it, and we'll see an example of parcelling off a header and footer into separate file.
You can use JSTL to do SQL stuff, querying and even updating database; thus encapsulating a lot of messy SQL in the page where it's actually used and taking a huge burden of complexity off your controller servlets or other auxiliary code.
It's time to take the image names we retrieved in the last tutorial and use them to actually display images. We'll also use the JSTL c:set tag to set the image names into a scoped variable which can then be used to display the images. Plus, a bit of a look at, in effect, concatenating strings in JSTL.
You can use a bunch of arithmetic operators and other stuff in EL; we'll see an example here in the course of putting our images into a grid.
The c:url tag both prefixes your context root and also adds on the jsessionid if necessary. We'll look at it in this tutorial.
You can use JDBC wildcards in JSTL; we'll look at it here, along with an example of getting a single row from a set of results.
JSTL includes some functions that you can use in EL, mostly connected to string handling. We'll take a look at a couple of examples here.
So far we've looked at SQL queries, and in this tutorial we'll go on to looking at an example of a SQL update. We'll also take a look at transactions, which enable us to execute a bunch of SQL statement which will either all succeed or else all fail; in the case of failure, the database is left in the same state that it was prior to the transaction.
Besides the "c" and "sql" tags in JSTL, there are also formatting tags. In this tutorial we'll format a number using JSTL.
You can create your own JSTL tags; in fact, you can create your own versions of every kind of tag we've seen. In this tutorial we'll take a look at a demo of creating a simple custom tag.
Congratulations on finishing the course!!! Many thanks for subscribing, and I hope you'll check out my courses in the future. In this final video I'll tell you about some other related technologies that might interest you, plus a few words about the job market.
In this video we'll look at how you can allow the user to upload files using Tomcat 6. The catch is, you either need to have a writeable directory on your server, or write some code to store uploaded files in MySQL. Assuming one of those, we'll take a look at how you can support upload forms with servlets.
NOTE: For Tomcat 7, see the second set of attached code to this lecture. Some things apparently changed in Tomcat 7, and the code I gave in this video no longer works.
After working as a software developer and contractor for over 14 years for a whole bunch of companies including CSC, Proquest, SPSS and AT&T in the UK and Netherlands, I decided to work full-time as a private software trainer. After spending four years in the beautiful city of Budapest, Hungary and a year in Berlin, I now live in my home town of Derby, UK.