Now let's take a look at JSP tags. After this lesson, you should be able to explain the difference between standard JSTL and custom tags, describe the primary reasons for using JSP tags and how they save us some time and effort, and write code to use beans and manipulate their properties, which is always a great skill. Let's take an overview of these. JSP tags are a special syntax to provide additional functionality. They just save us from writing scriptlets and expressions all over the place. There's a set of standard tags specified by Oracle, they're provided by the Web container, and one of the Libraries is the JSTL or JSP Standard Tag Library provided by Oracle. There are custom tags available with other frameworks; Java Server Faces and so on and part of other commercial products. There also can be custom tags written by you and while it's beyond the scope of this course, we strongly recommend you to take a stab at it after the course. You'll find that it's pretty straightforward and you can begin to create your own as needed, and they can be extremely useful. Again, the purpose is just to reduce or eliminate the use of scriptlets. Scriptlets can allow bad coding practices. I can start to put in a lot of code that shouldn't be there; talking to databases, skipping over my controller, putting in business logic, so that can be problematic. When I'm interweaving my scriptlets with HTML, it can get messy and I could miss a curly brace or something and it just gets tough to debug. Then of course as always I want to practice good MVC. We want really clean code especially if we're doing the repetitive stuff; looping over a collection, grabbing something out of the request or session scope. We just want to create consistent, easy-to-use tags so that we don't have to customize this over and over. Some of the benefits to remember are that ultimately, a JSP is a servlet, so everything you can do in a servlet, you can do in a JSP. Tags ultimately get translated to Java code. I don't have to learn another scripting language, I can just be a Java developer. They will help keep presentation, model, and controller code separate. A few key things that you want to remember though: don't apply your business logic inside your tags, don't make calls to data sources, don't make calls to external systems. We're really trying to keep this about presentation because don't forget, even though we have all this power, we're still in the Java Server Pages world and that's about presenting data. One of the things that we're going to use consistently is Java Beans. You may be already familiar with this. A Java Bean is just a plain old object that meets a standard. It has three big qualifiers : all the properties need to be private, it has a public no-arg constructor, and it implements serializable. You'll notice that our class Item implements serializable. It has private member level variables that have getters and setters. It has a no-arg constructor because we all know that if you don't put one in a class, one will be provided for you. That's your definition of a Java Bean. Now, how can we use it with these tags and start to do some pretty fun stuff? Jsp:useBean is a tag that can be used to get a bean from any scope; request, session, or application. If you pair that up with your implicit objects request, session, and application, you can begin to save yourself a lot of coding and scriptlet type manipulation. There's also a page scope in JSPs. If you want to really start to use that, it can be handy once in a while. Think of it as using "this" within the generated servlet. The way you would use "this" in a class, meaning the current instance that I'm working with, you can use the page scope to do that. UseBean will allow us to create and place a bean into any of the four scopes, and the bean would then be available to other container components. Pretty powerful. We don't have to start worrying about getting session and that kind of stuff. There are some attributes that we're going to take a look at here. We'll focus on the key ones, but we've given you one link here and there's more in the reading references for you to pursue. If you want to know more about how this works, there's several more attributes you can access. But if you take this line of code here on the bottom, jsp:useBean id, the id is the bean to find or create in the chosen scope. So if I have one, I'll recover it by this id, if I don't, I'll instantiate one of this type, com.store.model.Item. I'll put it in the session scope so it's available as an attribute. I can add my scope, I can add my class, and then I have a bean. Just a reminder, if a bean exists in the specified scope, it is retrieved, I get it back. If it doesn't exist, a new one will be created. Now, once I have that bean, I can also set properties on it. You'll notice that when we get to this part, the set property, the name attribute will have to match the id. Here's our line of code from the previous page and nothing has changed here, but now we're going to set the property with a request parameter value. Inside of our jsp:setProperty name equals, notice it matches the id, what property do you want to set? We want to set our item name. We had to have a property name that is a member level variable with the getter setter, that kind of thing. Now, this is just a param which came in off our request object. It was a request parameter that got passed into it. We're grabbing that request parameter and we're assigning that value to a property named item name inside our item class. Now, there are some nice shortcuts here, and this is where it can start to get a little bit fun. If the param names and property names match, if you're the Java developer, you can control both of these. So if you make sure that they match, there's a wildcard that will match all of your parameters. Even if I had five parameters that were coming in and five properties on my bean, I could set them all. Now, in this case, I'm just setting the one because it matches. But what if there were five, I could set them with this little wildcard here, which is pretty handy. The get property works much the same. You can output data to the client without a scriptlet or expression, that's pretty powerful. The name attribute must match the id of jsp:useBean. Here, I have my useBean. Again, we're still using the same one item, notice it's still in session. You added the following item, you say getProperty name item and you're adding it in here. We can use these in conjunction with our JSP page.