【发布时间】:2012-10-25 07:57:10
【问题描述】:
错误:不可转换的类型
我的 loginAction 文件的代码:
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws Exception
{
LoginForm loginForm = (LoginForm) form;
if (loginForm.getUserName().equals(loginForm.getPassword()))
{
return mapping.findForward(SUCCESS);
}
else
{
return mapping.findForward(FAILURE);
}
}
我的 struts-config 文件的代码:
<action-mappings>
<action input="/login.jsp" name="LoginForm" path="/Login" scope="session" type="com.strutsmyaction.LoginAction">
<forward name="success" path="/success.jsp" />
<forward name="failure" path="/failure.jsp" />
</action>
</action-mappings>
我的登录表单文件的代码
公共类登录表单 { 字符串用户名;字符串密码; 公共字符串 getUserName() { System.out.println("内部getter "+userName); 返回用户名; } 公共无效 setUserName(字符串用户名){ System.out.println("内部设置器"+userName); this.userName = 用户名; } 公共字符串 getPassword() { 返回密码; } 公共无效setPassword(字符串密码){ this.password = 密码; } }
【问题讨论】:
-
代码中的 SUCCESS 和 FAILURE(大写字母)是什么?
-
您使用的是 Struts 还是 Struts2?您的代码来自 Struts,但在您的问题中,您要求使用 Struts2 ...
-
为什么人们赞成这个?如果他不解释他使用的是哪个框架,这怎么可能是一个好问题?
-
我认为这个问题与数据转换有关。请发布 LoginForm 类和 html 表单元素。
-
再次检查代码,我将添加我的登录表单文件