Welcome to this lesson on writing Java applications, developing Java web and mobile applications. So there is a specific architecture that is not for Java alone. For web and most mobile applications there going to be what we call native mobile applications which run in only on the device that the user has. However, it quite, quite often mobile applications are architected the same way as a web application. They're just different ways to do it. The architecture is very, very similar to C# and Windows applications, also PHP. Many, many different types of web applications use the exact same architecture. We talked about this early on, we have the browser, which is the user layer. And that browser contacts many times, not always, but many times a web server. And there's also a web application server, and these two work together. The web server is almost, they call it a proxy, but it's like a traffic director. And depending on what the user requests, will direct traffic to the different application servers. There are static assets such as images, and then there's a database. A web server certainly can be optional, all web application servers come with their own web server. But there are a lot of advantages to proxing our application server with a web server. And again, the browser is most of the time considered the top layer of the architecture, whether this is a browser on a computer or on a mobile application. So Java web and mobile applications use the server and the server is a software application that in our case it's going to respond to HTTP requests. They can respond to other types of requests, but a web application server is going to respond to HTTP requests. Web application servers have libraries and APIs that support building our web and mobile applications. And our web application servers manage connections to the database. And with those connections to the database, with the way that the data comes back, they will build the pages of our web and mobile applications. So no data is actually stored on the server layer, all the data is sent to the database and queried from the database. Here are some examples of some popular Java-based web application servers. We can see here jBoss is very popular, WebLogic, WebSphere Application Server, Tomcat. We'll be using Tomcat in our exercise. Tomcat is also very popular, it's part of the Apache Foundation. And JDBC which is our Java database connection is a popular database driver for these web application servers. If we're using C sharp in the Windows world, IIS is the web application server. And most development environments, and I'm not aware of any exceptions, come with the way to integrate the web application servers with the IDE for the developer. So they can run right out, they can run the applications right out of the development environment. So in our case here we can see that we will integrate with Tomcat. We'll go to the Window menu, go to Preferences, and then we'll open up these preferences here. Go down to Server, and Runtime because the server is a runtime environment. And we will add in our web application server. So let's take a quick look about how it's done. So what we're going to do is, this is already been integrated. But we can take a look at the steps, we go to Windows, Preferences, and we go to Server. And we can see here, the server is down a little bit, we go to Runtime Environment. And we can select, and in this case we'll click Edit. We navigated to Apache Tomcat, an we also navigated to its Install directory, which is right here. And you can also add other web application servers which we'll select down here in our servers if you noticed that the Others available as well out of the box. Some of the types of pages that we are going to build, so there are some very popular frameworks that exist for Java. One of them is the Java server page or Jakarta server page, both JSP short for both. You may hear that JSP are old technology, they've been around awhile, but certainly not old technology. But the vendor is looking to rebrand them a bit, so you may see them called Jakarta server pages instead of Java server pages. JSP is nonetheless, and so webpage framework, based on again the servlet specification. So in Java, there is a class called the servlet and the servlet is a class that is for responding to certain types of requests. In our case ,our servlets are going to respond to HTTP requests. JSPs are related to some different type of a page called or a different type of a framework called the Java Server Faces or Jakarta Server Faces, and their JSPs are very, very similar to PHP or ASP. So you may recognize the pattern or may recognize the structure. JSPs embed Java code in something called scriptlets. And you can see an example of scriptlets here and they embed that Java code with HTML, and it's the exact same structure as PHP or .net. So we can take a look here, see our JSP, we see our Java code. These are often referred to as tags, where we have our Java code, the word scriptlet is many times avoided because we have that very popular JavaScript which is nothing to do with Java. There are similar in name, but in order to avoid confusion quite often when we were talking about Java, the term scriptlet is often avoided. You can see here it is a similar approach, we see our HTML, and we see our tags here, and we see our PHP code in between the tags surrounded by HTML. JSPs are compliant with the Model View Controller, the MVC, which is a popular framework for web pages. This is not Java specific, but we have some kind of a client that makes a call to a controller, quite often it's some kind of a servlet, JSP or a Bean which is another Java class, and makes a call back to a database. So this is how a JSP is compliant with the MVC. And JSPs are based on the Java servlet, they have a standard set of libraries, and we can see here the Java pages are based on the servlet. So JSP uses the servlet class again from behind the scenes, and we took a little bit at the tags of where the Java code is, but there are also variations of the tags. We can see here when we make a declaration, we can use a special type of tag for that declaration. So you can see it here with the <% exclamation to declare, in this case, we're declaring integer J. That's called declarative tag or declaration tag. And then there's a directive tag, which in this case, we can see here is the <%@, and we can include class libraries, and again, we can also use directive tags, and we can see here to import, also class our libraries. And then there's an expression tag, an expression tag does not have a semi colon in here at all. What it does, it returns a string, so we have to have a string in our expression tag. It is a shortcut for anything that would be out.print and the parameter in here. And again, there is no semi colon like we see here, so it is the <%= sign in here And this is our expression tag. You will see examples for all of these in this presentation and in our exercise. So we can take a look here. We can see there is HTML here for this JSP. Then we see our tags here our standard tags. And we can see here we are running some Java here with our if statements and output and back to the browser. And you can see here we have our HTML and we are using our our Java here to output to loop through were using a for loop here to output some kind of a list. These are list type of HTML tags. And just something that's a little more complete we have a full JSP page here. And what we're doing here is again, we're using our loop to output, just send some output back to the screen. You can see here one line that contains both a HTML. Here's our HTML. Here is an expression tag, and here is another. Here is our standard tags here. So you can see the out .print here is fully of you can see here it's fully read out, so then it has its semi colon here. And you can see here we just loop through a little counting. A accounting example. And notice here we are actually calling this JSP right here right from the URL. Java Server Faces or Jakarta Server Faces or another type of interface for our user. They have an API and a framework that includes the JSP and Servlets. You can see right here the Java Server Faces or Jakarta Server Faces JSFs are built on our JavaServer Pages are Servlets. They are designed to work with XML. So they work with an XML template called the Facelet. And again, they are designed to work closely with XML and Ajax. So data can actually be sent to the client side using XML files. So calls don't have to be made back to the server, so that makes it a lot faster. And JSFs have two major functions of to evoke a UI an also listener, listen for an act on user inputs and actions. So we can see here the browser is working closely with XML and we can see here, though response descending and then the response. So we could see here just some other examples that in this case button here is calling a create Student. And that obviously is a class, and that class is instantiated through a bin, which is a fancy term for a Java class. And then we see some navigation rules for that class that's running. Servlets, so we've been talking about Servlets and again a Servlet are a class that extends the abilities of a server. They listen for and respond to all different types of requests. But again, in our case is going to be HTTP requests. You'll often see servlets branded as Jakarta Servlets. Again, these are they're not going anywhere, they've been around, but I wouldn't say that they were old technology by any means. Like we said they can respond to any types of requests. But in our case, they will be responding to HTTP requests. Servlets again our framework and have their APIs for the web and mobile applications. They inherit from, in our case anyway, they inherit from the HTTP Servlet. So we'll actually see that an as we are creating them we can see here we can add well stubs, which is fine. It's all we need are stubs which gives us the header and four different methods. We definitely for HTTP for web and mobile we need to doPost and the doGet but I like to add the init as well. But notice there are even other HTTP requests in here we can add Methods for them and that's good because we can create advanced type of applications like similar to an API that can respond to different HTTP requests. When creating a servlet, it's a good idea to step entirely through the create servlet tool. [COUGH] sometimes is called a wizard. It's a good idea to go through all the pages, although you notice here on step 1 you can finish immediately. However, one thing about a servlet is it looks like just an ordinary Java class, with its class file. So we need to map it to the URL that the browser will be using to call the servlet. So we will put its location, in this case the package that the servlet is in. We will give it a name, click Next. And important here, we want to map it correctly. So what we want to do is it'll give us a suggestion for mapping. We can select that mapping and click Edit and update it. We can even add mappings. Then here we click Yes. Well, first we get the new mapping. Then we click Next. And here's where we can add other methods if we need to, and click Finish. And quite often what is really good for a web and mobile development is to have the init method, and the doPost, and the doGet. But again these are the base methods. We can add others if needed. And then when the server is created, we will have our methods here, our stubs. And you can see these are, there's no source code here. It's just the headers. But also notice here we have these annotations, which has our URL pattern and that's going to be important. In particularly for us, because we are going to be limited because our lab does not have full access to the outside world. So you got to do everything internally with Eclipse, so these annotations are going to help us quite a bit. And notice here our package it's our location is given to us. We get that as part of the creation and we also get our class is important. So something else about servlets are if we don't do the URL mapping, if we're not using Eclipse. If we're using something else, or if we're just using Notepad, we are going to have to use a deployment descriptor. And a deployment descriptor is a special file that lives in the WEB-INF for the web infrastructure directory. It's called web XML. And the web XML gives or provides the URL mappings for the servlets. And it also can provide URL mappings for JSPs as well. Now, again, we are not going to use a web.xml file in our lab. Because it does do some downloads, it will go out and try to download or make contact with some external repositories. So it will not work for us. But if you want to do this on your own, you can certainly go in and just add a web XML to your web infrastructure directory. This is what the web XML file looks like. So we have, you can see our servlet here. Our first set of tags here. We have the name, the servlet, so we give it a name. And we can name this anything really. It's most likely a good practice, I would say to name it after the servlet that you have the server file just so you don't have to think a lot and do some extra documentation. Next, we have to map the class path. So depending on how many packages and all that we got to put it in the class path just like this. Now this name is then going to be mapped to right here. This section, which is the servlet mapping. So this name you can see here is used. So we have to use that same name. So whatever we use up here, we have to use down here. And this class path is going to map to this URL pattern. So we Could see URL pattern servlet name servlet name servelet class and that again is the serverlet classpath so not too difficult of a concept. You can even see appear you can get really creative with your with your mappings. Also, you have these welcome files here, which you get for free when you use a eclipse to create the web XML file. One thing that is important to up here notice it is going out externally and this is our limitation for us. So we are not going to be able to get any work with the web XML file. Or if we take a look here notice here that we are making a call to this servlet. We can see here that in our Java project we can see the mapping here we can see it's Classpath was proc.servletBasics. And we mapped URL pattern here to Proc demo basics so we can see here and it's returning this so the way that this servlet class is called instantiate by the browser is by this URL pattern. And again, this is with the XML file that we are going to have to build now. In our case, since we use that create servlet wizard, we are going to go in and make sure that we map all of our servlets correctly. Eclipse takes care of this for us. And again we can see here the classpath in this case, we could see is proc and basic servlet. And you can see here basic servlet dot Java and this annotation right here is what eclipse is doing for us. So this is important If we did not have eclipse to rely on we would have to be using the web.xml file. It's always a good practice to use the web.xml file, again that's called the deployment descriptor. And you can also use the deployment descriptor for URL patterns for JSP files. So notice here we have this mapping and we're going start and there's an index JSP. And notice it says here these tags here JSP files and we look down here again to the name. The URL mapping is slashed base. So one thing that's important now as we are posting or getting whereas we're making our requests that we use this URL pattern to make our request and not the JSP file name. If we want the URL pattern that we have set up here in the web.xml file. And again, you can see it here as well. You can have our select order, which is going to be our servlet name, although this is JSP we still use servlet name. One time here, we make the request with the JSP name and that works, but with this mapping here. We can also use this other URL pattern and anytime we make the request moving forward we don't want to call the JSP like we're doing up here. We want to call enter order. So our next up we are going to build a web or we're going to use eclipse to build a web application and we're going to work with JSP s and servlets. Please complete the lab and please watch any other remaining videos, complete any readings and please complete the quiz