In this excerpt from chapter 4 of Joel Murach's Java Servlets and JSP, you'll learn how to develop a web application that consists of HTML pages and JavaServer Pages (JSPs). As you will see, JSPs work fine as long as the amount of processing that's required for each page is limited. When you complete this chapter, you should be able to use JSPs to develop simple web applications of your own.
After you create a JSP, you need to test it. One way to do that is to click on a link or a button on an HTML page that requests the JSP. Another way is to enter a URL into a web browser that requests the JSP. Figure 7 shows how to request a JSP either way.
When you use the Get method to request a JSP from an HTML form, the parameters are automatically appended to the URL.
When you code or enter a URL that requests a JSP, you can add a parameter list to it starting with a question mark and with no intervening spaces. Then, each parameter consists of its name, an equals sign, and its value. To code multiple parameters, use ampersands (&) to separate the parameters.
To request a JSP from an HTML form, you use the Action attribute of the form to provide a path and filename that point to the JSP. This is illustrated by the first example in this figure. Here, the assumption is that the HTML page and the JSP are in the same directory. If they weren't, you would have to supply a relative or absolute path for the JSP file.
To request a JSP by entering its URL into a browser, you enter an absolute URL as shown by the next two examples in this figure. The first example shows the URL for the JSP when it's stored on a local web server in the email4 directory of the murach directory. The second example shows the URL for the JSP if the JSP was deployed on the Internet server for www.murach.com.
When you test a JSP by entering a URL, you will often want to pass parameters to it. To do that, you can add the parameters to the end of the URL as shown by the last examples in this figure. Here, the question mark after the jsp extension indicates that one or more parameters will follow. Then, you code the parameter name, the equals sign, and the parameter value for each parameter that is passed, and you separate multiple parameters with ampersands (&). If you omit a parameter that's required by the JSP, the getParameter method will return a null value for that parameter.
When you use a Get method to request a JSP from another page, any parameters that are passed to the JSP will be displayed in the browser's URL address. In this figure, for example, you can see the first two parameters that have been attached to the URL. However, in the next figure, you'll learn that the Post method works differently.
Remember: this is from chapter four ofJoel Murach's Java Servlets and JSP (Mike Murach & Associates, ISBN 1890774189, 2003). Grab a copy at your favorite book store today!