用JBuilder X 做一个简单的Struts应用,捆绕俺N久!

wanchengpeng 2005-06-28 04:44:19
我在JBuilder下用Struts模式做一个身份验证,总是出现莫名其妙的错误,请高手指点!
[==========这是含有表单的JSP页面代码================]
<font color="red" size="10pt"><html:errors/></font>
<div align="center">
<table width="776" height="300" border="0" cellpadding="0" cellspacing="0">
<tr>
<TD width="18" background="image/bg1222.jpg"> </TD>
<td align="center" valign="middle" width="740">
<table width="360" align="center" height="90">
<script language="javascript" src="scripts/UserCheck.js"></script>
<FORM name="LOGIN" onsubmit="if(LoginFormTest()==false) return false;" action="userLoginAction.do" method="post">
<tr>
<td width="174" align="right" valign="middle"><span class="style7">用户名:</span></td>
<td width="174" align="left" valign="middle"><INPUT style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; BORDER-LEFT: #808080 1px solid; WIDTH: 96px; BORDER-BOTTOM: #808080 1px solid; HEIGHT: 20px; BACKGROUND-COLOR: #ffffff" maxLength="32" name="name"><html:errors property="name"/></td>
</tr>
<tr>
<td align="right" valign="middle"><span class="style7">密  码:</span></td>
<td align="left" valign="middle"><INPUT style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; BORDER-LEFT: #808080 1px solid; WIDTH: 96px; BORDER-BOTTOM: #808080 1px solid; HEIGHT: 20px; BACKGROUND-COLOR: #ffffff" type="password" maxLength="32" name="passwd"><html:errors property="passwd"/></td>
</tr>
<tr>
<td align="right" valign="middle"><span class="style7">验证码:</span></td>
<td align="left" valign="middle">
<INPUT style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; BORDER-LEFT: #808080 1px solid; WIDTH: 36px; BORDER-BOTTOM: #808080 1px solid; HEIGHT: 20px; BACKGROUND-COLOR: #ffffff" maxLength="4" size="4" name="checkcode"><img alt="验证码" src="CheckCode.jsp" border="0"/><html:errors property="checkCode"/>
</td>
</tr>
<tr>
<td align="right" valign="middle"></td>
<td align="left" valign="middle"><input type="submit" name="Submit" value="提交"></td>
</tr>
<tr>
<td colspan="2" align="center" valign="middle"><a href="Register.jsp" class="link1">没有注册?点此处注册</a></span></td>
</tr>
</form>
</table>
[==========这是ActionFrom的代码================]
public ActionErrors validate(ActionMapping actionMapping, HttpServletRequest httpServletRequest) {
/**@todo: finish this method, this is just the skeleton.*/
ActionErrors errors=new ActionErrors();
if(this.name==null){
errors.add("name",new ActionMessage("userLogin.name.incorrect"));
return errors;
}
if(this.passwd==null){
errors.add("password",new ActionMessage("userLogin.password.incorrect"));
return errors;
}
if((this.checkcode==null)){
errors.add("checkCode",new ActionMessage("userLogin.checkCode.incorrect"));
return errors;
}
HttpSession session=httpServletRequest.getSession();
if(session.getAttribute("checkCode").toString()!=checkcode){
errors.add("checkCode",new ActionMessage("userLogin.checkCode.incorrect"));
return errors;//就这里!!!这里一返回,就出现错误
}
return null;
}
[==========这是Action中的代码================]
public ActionForward execute(ActionMapping actionMapping, ActionForm actionForm, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) {
/**@todo: complete the business logic here, this is just a skeleton.*/
userLoginActionForm userLoginActionForm = (userLoginActionForm) actionForm;
MessageResources message=getResources(httpServletRequest);
ActionMessages errors=new ActionMessages();
UserLoginBean userLogin=new UserLoginBean();
String name=userLoginActionForm.getName();
String passwd=userLoginActionForm.getPasswd();

if(userLogin.userLoginIn(name,passwd)){
return(new ActionForward(actionMapping.getInput()));
}else{
return(actionMapping.findForward("userLogin"));
}
}
声明:我是超级草鸟,问题一大堆,请大家多多指教!!!
...全文
442 10 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
wanchengpeng 2005-06-30
  • 打赏
  • 举报
回复
>airhand(暴风雨) ( ) 信誉:100 2005-6-28 21:54:30 得分: 0
>MessageResources message=getResources(httpServletRequest);是不是有问题?
>或者你的属性文件有中文,应该编码一下,否则是乱码!
>你为什么不调试一下,看看ACTION哪里错了呢?

出错的地方在这里:
if(session.getAttribute("checkCode").toString().equalsIgnoreCase(checkcode)){
errors.add("checkCode",new ActionMessage("userLogin.checkCode.incorrect"));
return errors;//就这里!!!这里一返回,就出现错误
}

也就是说,只要在ActionForm中return一个错误,就会出现抛出异常!



大河V5 2005-06-29
  • 打赏
  • 举报
回复
属性文件没有unicode化啊!
native2ascii -encoding gb2312 ApplicationResources_ascii.properties ApplicationResources.properties
wanchengpeng 2005-06-29
  • 打赏
  • 举报
回复
我来顶一下,别让帖子沉下去了,嘿嘿^_^
请大家继续关注,多多指点!
wanchengpeng 2005-06-29
  • 打赏
  • 举报
回复
请大家继续关注,多多指点~~~~
lifeng800 2005-06-28
  • 打赏
  • 举报
回复
up
airhand 2005-06-28
  • 打赏
  • 举报
回复
MessageResources message=getResources(httpServletRequest);是不是有问题?
或者你的属性文件有中文,应该编码一下,否则是乱码!

你为什么不调试一下,看看ACTION哪里错了呢?
wanchengpeng 2005-06-28
  • 打赏
  • 举报
回复
mofeir(莫飞) 高见何解?
mofeir 2005-06-28
  • 打赏
  • 举报
回复
建议改名 (万程鹏) -->> (一米鸟)
wanchengpeng 2005-06-28
  • 打赏
  • 举报
回复
在JBuilderX中运行时,Tomcat有如下提示信息是红色的:
2005-6-28 16:53:38 org.apache.struts.util.PropertyMessageResources <init>

信息: Initializing, config='org.apache.struts.util.LocalStrings', returnNull=true

2005-6-28 16:53:38 org.apache.struts.util.PropertyMessageResources <init>

信息: Initializing, config='org.apache.struts.action.ActionResources', returnNull=true

2005-6-28 16:53:38 org.apache.struts.util.PropertyMessageResources <init>

信息: Initializing, config='ApplicationResources', returnNull=true
2005-6-28 16:53:49 org.apache.struts.util.PropertyMessageResources <init>

信息: Initializing, config='org.apache.struts.taglib.html.LocalStrings', returnNull=true


wanchengpeng 2005-06-28
  • 打赏
  • 举报
回复
[=============这是ApplicationResources.properties中的内容==============]
#-- titles --
title.userLogin=用户登陆信息

#-- messages --

#-- error messages --
userLogin.name.incorrect=请输入正确的用户名!
userLogin.password.incorrect=请输入正确的用户密码!
userLogin.checkCode.incorrect=请输入正确的校验码!
userLogin.incorrect=请输入正确的登陆信息!

#-- errors headers

81,122

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧