hi friends
normally in
spring's simple form controller we are registering one command object for one controller
like following code
<beanid="loginController"
class ="com.dss.ems.controllers.LoginController">
<property name="sessionForm"><value>true</value></property>
<property name="commandName"><value>usermodel</value></property>
<property name="commandClass"><value>com.dss.ems.models.UserModel</value></property> but in multiaction controller how should we proceed to register one command object for one method
i will give u one example
my Controller code is public class LoginController extends MultiActionController{
private Map userMap=null;
public LoginController() {
System.out.println(" In LoginController ");
}
public ModelAndView showLoginPage(HttpServletRequest request,
HttpServletResponse response,
Object obj) throws ServletException {
System.out.println("i am giving login page");
ModelAndView mav=new ModelAndView("login");
mav.addObject("usermodel",new UserModel());
return mav;
}
// problem part
public ModelAndView authenticateUser(HttpServletRequest request,
HttpServletResponse response,
Object command){
System.out.println(" iam in authentication"+command.getClass());
UserModel loginCommand = (UserModel) command;
// in user map we set the username as key
if( loginCommand.getUserName()!=null &&
loginCommand.getPassword()!=null &&
(loginCommand.getPassword()).equals(
(this.getUserMap()).get(loginCommand.getUserName() ))
) {
System.out.println("you are valid user");
return new ModelAndView("Expense");
}
else {
System.out.println("you are NOT valid user");
//throw new UserNotFoundException();
return new ModelAndView("login");
}
}
public void setUserMap(Map userMap) {
this.userMap =userMap;
}
public Map getUserMap() {
return this.userMap;
}
}
MY JSP PAGE IS <%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<%@ taglib prefix="spring" uri="/spring" %>
<html>
<head>
<title>
Login to Expense Management System
</title>
</head>
<body>
<table width="742" border="0" cellspacing="0" cellpadding="0">
<tr>
<td colspan="2" style="color:#FFFFFF;background-color:#666699;height:100px;"><span style="font-size:24pt;">
EXPENSE MANAGEMENT SYSTEM
</td>
</tr>
<tr>
<td width="742" valign="top">
<table width="742" border="0" cellspacing="0" cellpadding="0">
<tr>
<td
style="font-size:14pt;color:#FFFFFF;background-color:#9999CC;" align="right">
Login
</td>
</tr>
<tr>
<td valign="top" style="font-size:10pt;" align="center">
<form method="POST"
action="auth.htm">
<table width="400"
border="0"
cellspacing="5"
cellpadding="0">
<tr>
<td align="right" valign="middle">
<b>Login:</b>
</td>
<td align="left" valign="middle">
<spring:bind path="usermodel.userName">
<input type="text"
name="<cut value="${status.expression}"/>" value="<cut value="${status.value}"/>">
</spring:bind>
</td>
</tr>
<tr>
<td align="right" valign="middle">
<b>Password:</b>
</td>
<td align="left" valign="middle">
<spring:bind path="usermodel.password">
<input type="password"
name="<cut value="${status.expression}"/>" value="<cut value="${status.value}"/>">
</spring:bind>
</td>
</tr>
<td colspan="2" align="center">
<input type="submit">
</td>
</table>
</form>
<br>
<br>
<a href=""><B>FORGOT PASSWORD</B></a>.
<br><br>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
AND XML FILE IS <beans>
<bean id="simpleUrlMapping"
class = "org.springframework.web.servlet.handler.SimpleUrl HandlerMapping">
<property name ="mappings">
<props>
<prop key ="login.htm">loginController</prop>
<prop key ="auth.htm">loginController</prop> </props>
</property>
</bean>
<!-- ========================= CONTROLLER DEFINITIONS ========================= -->
<bean id="loginController"
class ="com.dss.ems.controllers.LoginController">
<property name="methodNameResolver" ref="LoginControllerMethodNameResolver"/>
<property name="userMap">
<map>
<entry>
<key><value>gp</value></key>
<value>gp</value>
</entry>
<entry>
<key><value>jk</value></key>
<value>jk</value>
</entry>
<entry>
<key><value>sb</value></key>
<value>sb</value>
</entry>
<entry>
<key><value>dd</value></key>
<value>dd</value>
</entry>
</map>
</property>
</bean>
<!-- =========================Method name resolver ========================= -->
<bean id="LoginControllerMethodNameResolver"
class="org.springframework.web.servlet.mvc.multiac tion.PropertiesMethodNameResolver">
<property name="mappings">
<props>
<prop key="/login.htm">showLoginPage</prop>
<prop key="/auth.htm">authenticateUser</prop> </props>
</property>
</bean>
<!--
<bean id="loginFormValidator"
class="com.dss.ems.formvalidators.LoginFormValidat or"/>
-->
<bean id="viewResolver"
class = "org.springframework.web.servlet.view.InternalReso urceViewResolver">
<property name="viewClass">
<value>org.springframework.web.servlet.view.JstlVi ew</value>
</property>
<property name ="prefix">
<value>/jsp/</value>
</property>
<property name ="suffix">
<value>.jsp</value>
</property>
</bean>
</beans>
AND ERROR ON SERVER SIDE IS INFO: Using JSP 2.0 ExpressionEvaluator
iam in authentication class java.lang.Object 14-Dec-2005 14:27:16 org.springframework.web.servlet.FrameworkServlet processRequest
SEVERE: Could not complete request
java.lang.ClassCastException
at com.dss.ems.controllers.LoginController.authentica teUser(LoginController.java:
at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.j
at java.lang.reflect.Method.invoke(Method.java:324)
at org.springframework.web.servlet.mvc.multiaction.Mu ltiActionController.invokeNa
Controller.java:403)
at org.springframework.web.servlet.mvc.multiaction.Mu ltiActionController.handleRe
tionController.java:358)
at org.springframework.web.servlet.mvc.AbstractContro ller.handleRequest(AbstractC
at org.springframework.web.servlet.mvc.SimpleControll erHandlerAdapter.handle(Simp
apter.java:44)
at org.springframework.web.servlet.DispatcherServlet. doDispatch(DispatcherServlet
problem is that how should i tell my MultiActionController Command Object is Of type com.dss.ems.models.Usermodel and not java.lang.Object please help me friends
[ December 12, 2005: Message edited by: ganesh pol ]
[ December 14, 2005: Message edited by: ganesh pol ]