* Beware, servlets are placed in a servlets

* Beware, servlets are placed in a servlets (plural) directory but are invoked with a servlet (singular) tag. If you think about it, this makes a certain amount of sense, as servlets go in the servlets directory while a single servlet is referenced with the servlet. Handling Form Data The “Hello World” servlet is not very exciting, so let’s try something slightly more ambitious. This time we’ll create a servlet that greets the user by name. It’s not hard. First, we need an HTML form that asks the user for his or her name. The following page should suffice: Introductions

If you don’t mind me asking, what is your name?

Figure 2-4 shows how this page appears to the user. Figure 2-4. An HTML form When the user submits this form, his name is sent to the Helloservlet because we’ve set the ACTIONattribute to point to the servlet. The form is using the GET method, so any data is appended to the request URL as a query string. For example, if the user enters the name “Inigo Montoya,” the request URL is http://server:8080/servlet/Hello?name=Inigo+Montoya. The space in the name is specially encoded as a plus sign by the browser because URLs cannot contain spaces. A servlet’s HttpServletRequestobject gives it access to the form data in its query string. Example 2-2 shows a modified version of our Helloservlet that uses its request object to read the “name” parameter. Example 2-2. A servlet that knows to whom it’s saying hello
Note: If you are looking for cheap and inexpensive provider to host and run your tomcat application check professional tomcat hosting services

Comments are closed.