Java Reference
In-Depth Information
The line:
<form action="output.jsp">
Needs to be modified as follows:
<form action="ControllerServlet" method="post">
What we did was change the value of the action attribute of the HTML <form>
element to be the URL of our servlet (we defined this URL in the servlet wizard
when we were creating our servlet; it is permanently stored in the application's
web.xml configuration file).
<servlet-mapping>
<servlet-name>ControllerServlet</servlet-name>
<url-pattern>/ControllerServlet</url-pattern>
</servlet-mapping>
Additionally, we added a method attribute to the <form> element, and gave it a
value of post . This step wasn't strictly necessary, however by default a form uses a
method of get , and HTTP GET requests have a disadvantage: parameter names and
values are shown in the browser's location text field, and malicious user's might
attempt to break our application by modifying the displayed URL by giving invalid
values to the request parameters. HTTP POST requests have no such disadvantage;
therefore it is a good idea to use POST requests whenever possible.
We also need to make a few modifications to the output JSP so that it retrieves values
from the JavaBean that is stored.
The first thing we need to do is to add a <jsp:useBean> tag to our JSP. This tag can
be either typed in directly, or can be dragged from the palette and dropped into the
page. Dragging and dropping the tag into the page results in the following window
popping up.
 
Search WWH ::




Custom Search