Create JSP file
Posted on: December 2, 2010 at 12:00 AM
In this tutorial you will learn how to create a JSP file in struts2

Create a JSP file

To create a JSP file for struts, Some special (Struts specific) tags are used. And to use those tags in JSP you need to import there tag library. struts-tags is the tag library which contains all the struts specific html tags. This tag is User Interface (UI) tag used to make the form or other html pages. To use this tag you need to write <%@ taglib prefix="s" uri="/struts-tags" %> and also do mapping for StrutsPrepareAndExecuteFilter in web.xml file. as



If you not do such type of mapping then it may caused an error The Struts dispatcher cannot be found

A simple login page is give below which illustrates how to use the struts-tags


<%@ taglib prefix="s" uri="/struts-tags" %>
<title>Tets JSP Page </title>
<body bgcolor="lightblue"><br><br><br><br><br>
<s:form action="login" method="POST">
<table border=0 align="center">
<td><s:actionerror /></td>
<td><s:fielderror /></td>

<td><s:textfield name="userName" label="User Name"/></td>
<td><s:password name="password" label="Password"/></td>
<td><s:submit align="center" value="login"/></td>

In the login page <s:form action="login" method="POST">  indicates the form. The form action is login, this is the name of the action, which is you will map in the struts.xml file. and on submitting the form will call that (login) action.

the tag  <s:actionerror /> and <s:fielderror /> indicates that if there is any error in form action or field that will be displayed by this tag.

In the tag <s:textfield name="userName" label="User Name"/>, textfield, password indicates the type of the fiels and password respectively. label indicates the name of the label shown on the page indicating the field. s:submit indicates the submit button which submits the form.

finally closing the form using </s:form>

You can learn more about struts-tags on

Or on

Download this example code

Related Tags for Create JSP file:




Advertisement null