Write A First Input View (JSP Page)

Write A First Input View (JSP Page)

Previous Home Next

 

In this section we are going to create a First Input View using Struts Framework. We are creating here first login form using Struts Framework. So that the user can submit user name and password.


 To make login form (First input View) using Struts Frameworks is similar to HTML Form Tag.You might be worked on a form in which we had made input fields, Checkboxes, radio button etc. using HTML Tags.Struts provide different tag libraries to make View. Struts provides HTML tag library to make Input JSP View. Struts provides following renders tags for html tags.There are many more others which we will cover in our next section in more details To use the Struts Tag Libraries we have first copy and past struts jar (e.g. struts-taglib-1.3) into lib folder Then configure it in web.xml and add tag library into the JSP page. Then start making login form. You can copy and past following code. Next Step you have makes subclass of ActionForm and Action and configures it into struts-config.xml. which we will cover into next section. We will cover also validations and error handling in next sections. At the time of “Action Mappings Configuration” we have input attributes in action tag. Like in struts-config.xml we have add<!-- Action Mappings Configuration -->

index.jsp

<%@taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<html>
<head>
<title>Login Form</title>
</head>
<body>
<html:form action="/login" >
<table  border="1" bordercolor="red">
<tr> <td align="center" height="50px" style="background: gray;">
Login Example in Struts 1.3</td> </tr>
<tr><td align="center" width="250px" height="150px" style="background: gray;">
<table>
<tr> <td>User Name</td> 
<td><html:text name="loginForm" property="name"/></td> </tr> 
<tr> <td>Password</td> 
<td> <html:password name="loginForm" property="password"/></td> </tr>
 <tr> <td colspan="2" align="right">
<html:submit value="login"/></td> </tr>
</table></td></tr>
</table>
</html:form>
</body>
</html>

success.jsp

<%@taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%>
<h4>You are successfully Login</h4>
<h5>Welcome, <bean:write name="loginForm" property="name"/></h5>

error.jsp

<h4 style="color: red;">Invalid UserName and Password</h4>
<jsp:include page="index.jsp"></jsp:include>

Output



Previous Home Next