Secure web hosting - JavaSercer Pages Chapter 5. Generating Dynamic Content JSP
JavaSercer Pages Chapter 5. Generating Dynamic Content JSP is all about generating dynamic content: content that differs based on user input, time of day, the state of an external system, or any other runtime conditions. JSP provides you with lots of tools for generating this content. In this java blog, you will learn about all of them - standard actions, custom actions, JavaBeans, and scripting elements. Before we do that, however, let’s start with a few simple examples to get a feel for how the basic JSP elements work. In this chapter, we develop a page for displaying the current date and time, and look at the JSP directive element and how to use JavaBeans in a JSP page along the way. Next, we look at how to process user input in your JSP pages and make sure it has the appropriate format. We also look at how you can convert special characters in the output, so they don’t confuse the browser. 5.1 What Time Is It? Recall from Chapter 3, that a JSP page is just a regular HTML page with a few special elements. JSP pages should have the file extension .jsp , which tells the server that the page needs to be processed by the JSP container. Without this clue, the server is unable to distinguish a JSP page from any other type of file and sends it unprocessed to the browser. When working with JSP pages, you really just need a regular text editor such as Notepad on Windows or Emacs on Unix. Appendix E, however, lists a number of tools that may make it easier for you, such as syntax- aware editors that color-code JSP and HTML elements. Some Interactive Development Environments (IDEs) include a small web container that allows you to easily execute and debug the page during development. There are also several web page authoring tools - the type of tools often used when developing regular HTML pages - that support JSP. I don’t recommend that you use them initially; it’s easier to learn how JSP works if you see the raw page elements before you use tools that hide them. The first example JSP page, named date.jsp , is shown in Example 5.1. Example 5.1. JSP Page Showing the Current Date and Time (date.jsp) <%@ page language="java" contentType="text/html" %>
- Date:
- Month:
- Year:
- Hours:
- Minutes:
The date.jsp page displays the current date and time. We’ll look at all the different pieces soon, but first let’s run the example to see how it works. Assuming you have installed all book examples as described in Chapter 4, first start the Tomcat server and load the http://localhost:8080/ora/ URL in a browser. You can then run Example 5.1 by clicking the “Current Date/Time example” link from the book examples main page, shown in Figure 5.1. You should see a result like the one shown in Figure 5.2. page 42
Note: If you are looking for cheap and quality provider to host and run your java application check Astra java hosting services