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 defined as the value of the urlPatterns
attribute of the generated @WebServlet annotation.
@WebServlet(name = "ControllerServlet", urlPatterns = {"/
ControllerServlet"})
public class ControllerServlet extends HttpServlet {
}
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 get method, and HTTP GET requests have a disadvantage, parameter names and
values are shown in the browser's location text field, and malicious users 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
to popping up:
 
Search WWH ::




Custom Search