Forms without servlets

In JSP it is also possible to use Beans without using servlets. In this JSP tutorial we’ll demonstrate how this is done.

We’ll be using the same form as in the previous tutorial. The only difference is the target for the form. You’ll have to change this to processform.jsp.

The processform JSP will take over the things that the servlet did. This means: define the Bean and stuff it with data.

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<jsp:useBean id="formDataBean" scope="session" />
<jsp:setProperty name="formDataBean" class="beans.FormDataBean property="*"/>
<html>
  <head><title>Form without servlet</title></head>
  <body>

    <a href="showdata.jsp">Show data</a>

  </body>
</html>

By calling the “setProperty” command the formDataBean will look for all the parameters that were giving to this request and all parameters that have the same name as one of the properties from the formDataBean will be inserted in the formDataBean.

As you can see in this tutorial there’s two ways to process data in jsp. One way is to use a servlet and enter the data in a Bean, the other way is to use a JSP to insert the data in a Bean.