Hello javaranchers
I have created one login form ,success and failure page but whatever i type in login or password fields,control transfer to failure page why is it so?
and one more thing whenever i run the program there is already user name and password come in the two fields which i have entered last time how to clear the two field for every run?
here is the code
loginform.jsp
<%@taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
<html:html>
<body>
<html:form action="/LogIn.do">
UserName : <html:text property="username" size="20" /> <br/>
<html:errors property="username"/>
Password : <html
assword property="password" size="20" /> <br/>
<html:errors property="password"/>
<html:submit>LogIn</html:submit>
</html:form>
</body>
</html:html>
LogInAction.java
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
LogInActionForm frm=(LogInActionForm)form;
if(frm.getUsername().equals("Scott") && frm.getPassword().equals("Tiger")){
SUCCESS="equal";
} else{
SUCCESS="Notequal";
}
return mapping.findForward(SUCCESS);
}
}
Struts-config.xml file
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD
Struts Configuration 1.2//EN"
"http://jakarta.apache.org/struts/dtds/struts-config_1_2.dtd">
<struts-config>
<form-beans>
<form-bean type="com.myapp.struts.LogInActionForm" name="LogInActionForm"/>
</form-beans>
<global-exceptions>
</global-exceptions>
<global-forwards>
<forward name="welcome" path="/Welcome.do"/>
</global-forwards>
<action-mappings>
<action type="com.myapp.struts.FirstAction" path="/First">
<forward name="ok" path="/Success.jsp"/>
<forward name="notOk" path="/Fail.jsp"/>
</action>
<action input="/LoginForm.jsp" type="com.myapp.struts.LogInAction"
scope="session" path="/LogIn" name="LogInActionForm">
<forward name="equal" path="/Success.jsp"></forward>
<forward name="Notequal" path="/Fail.jsp"></forward>
</action>
<action path="/Welcome" forward="/welcomeStruts.jsp"/>
</action-mappings>
<controller processorClass="org.apache.struts.tiles.TilesRequestProcessor"/>
<message-resources parameter="com/myapp/struts/ApplicationResource"/>
<!-- ========================= Tiles plugin ===============================-->
<!--
This plugin initialize Tiles definition factory. This later can takes some
parameters explained here after. The plugin first read parameters from
web.xml, thenoverload them with parameters defined here. All parameters
are optional.
The plugin should be declared in each struts-config file.
- definitions-config: (optional)
Specify configuration file names. There can be several comma
separated file names (default: ?? )
- moduleAware: (optional - struts1.1)
Specify if the Tiles definition factory is module aware. If true
(default), there will be one factory for each Struts module.
If false, there will be one common factory for all module. In this
later case, it is still needed to declare one plugin per module.
The factory will be initialized with parameters found in the first
initialized plugin (generally the one associated with the default
module).
true : One factory per module. (default)
false : one single shared factory for all modules
- definitions-parser-validate: (optional)
Specify if xml parser should validate the Tiles configuration file.
true : validate. DTD should be specified in file header (default)
false : no validation
Paths found in Tiles definitions are relative to the main context.
-->
<plug-in className="org.apache.struts.tiles.TilesPlugin" >
<set-property property="definitions-config" value="/WEB-INF/tiles-defs.xml" />
<set-property property="moduleAware" value="true" />
</plug-in>
<!-- ========================= Validator plugin ================================= -->
<plug-in className="org.apache.struts.validator.ValidatorPlugIn">
<set-property
property="pathnames"
value="/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml"/>
</plug-in>
</struts-config>
please solve my problem
Thanks
Shikha