My example
struts application is not working...after entering the username and usercode and clicking on submit I got the blank page..some one help me..
CODE:::
This is my
JSP - LoginView.jsp
<%@ taglib uri="/WEB-INF/taglib/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/taglib/struts-bean.tld" prefix="bean" %>
<html>
<head>
<link rel="stylesheet" href="./jsp/display/ie.css"/>
<title>>My First Struts Program</title>
</head>
<body>
<h4>My First Struts Program</h4>
<fieldset>
<legend class="body">Login Form</legend>
<html:errors />
<html:form action="login.do">
<table width="100%">
<tr>
<td class="body">User Name</td>
<td class="body"><html:text property="username" size="14" styleClass="body"/></td>
</tr>
<tr>
<td class="body">User Code</td>
<td class="body"><html
assword property="usercode" size="14" value="" styleClass="body"/></td>
<tr>
<tr>
<td><html:submit property="valid" value="Validate" styleClass="body"/></td>
</tr>
</table>
</html:form>
</fieldset>
</body>
</html>
This is my FormBean - LoginForm.java
package myTest.struts;
import org.apache.struts.action.ActionForm;
public class LoginForm extends ActionForm
{
private
String userName;
private int userCode;
public void setUsername(String uname)
{
userName=uname;
}
public String getUsername()
{
return userName;
}
public void setUsercode(int ucode)
{
userCode=ucode;
}
public int getUsercode()
{
return userCode;
}
}
This is my Action - LoginAction.java
package myTest.struts;
import javax.servlet.*;
import javax.servlet.http.*;
import org.apache.struts.action.*;
import myTest.struts.LoginBean;
public class LoginAction extends Action
{
public LoginAction()
{
}
public ActionForward perform(ActionMapping mapping, ActionForm form,HttpServletRequest request, HttpServletResponse response) throws java.io.IOException, javax.servlet.ServletException
{
LoginBean lb = new LoginBean();
request.setAttribute("LoginBean", lb);
lb.setParameters(request);
System.out.println("Inside action");
ActionErrors ae = lb.validate();
request.setAttribute(Action.ERROR_KEY, ae);
if (ae == null || ae.size() == 0)
{
return mapping.findForward("valid");
}
else
{
return mapping.findForward("invalid");
}
}
}
This is validator - LoginBean.java
package myTest.struts;
import javax.servlet.http.*;
import org.apache.struts.action.*;
public class LoginBean
{
String userType, userName ,userCode;
public LoginBean()
{
}
public void setParameters(HttpServletRequest request)
{
userName = request.getParameter("username");
userCode = request.getParameter("usercode");
System.out.println("Inside bean set param");
}
public ActionErrors validate()
{
if (!userName.equals(userCode))
{
ActionErrors ae = new ActionErrors();
ae.add("userName", new ActionError("error.invalid.login"));
return ae;
}
if (userName.equals("admin"))
{
userType = "Adminstrator";
}
else
if (userName.equals("user")) {
userType = "User";
}
else
{
ActionErrors ae = new ActionErrors();
ae.add("userName", new ActionError("error.invalid.login"));
return ae;
}
return null;
}
public String getUserType() {
return userType;
}
public void setUserType(String userType)
{
this.userType = userType;
}
}