Servlet.service() for servlet action threw exception出错!!!! 急喔
*/
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
DynaValidatorForm loginForm = (DynaValidatorForm) form;// TODO Auto-generated method stub
String username=loginForm.getString( "userName ");
String password=loginForm.getString( "password ");
if(request.getAttribute( "rand ").equals(loginForm.getString( "rand "))&&userServiceImp.isUser(username, password))
{ HttpSession session=request.getSession();
Users us=userServiceImp.getUsersDAO().findByUName(username);
ApplicationContext context = new FileSystemXmlApplicationContext( "C://workspace//bookstore//WebRoot//WEB-INF//applicationContext.xml ");
RandomValus randomValus=new RandomValus();
MD5 md5=new MD5();
String code=md5.getMD5Instance().compute(randomValus.getRandomStr()).toUpperCase();
session.setAttribute( "name ",username);
session.setAttribute( "code ", code);
MapperIF mapper =(MapperIF)context.getBean( "net.sf.dozer.util.mapping.MapperIF ");
Users_static users_static= (Users_static) mapper.map(us,Users_static.class);
Vector userslist=new Vector();
userslist.add(users_static);
session.setAttribute( "users ", userslist);
return mapping.findForward( "success ");}
else return mapping.findForward( "faild ");
}
}
我的login.jsp
<h5> 登录 </h5>
<form id= "form1 " method= "post " action= "login.do ">
<label> 用户名
<input name= "userName " type= "text "/>
<a href= "register_step_one.do " target= "_blank " class= "font00F "> 注册新用户 </a> </label>
<label> 密 码
<input name= "password " type= "password "/>
</label>
<label> 验证码
<input name= "rand " size= "5 " type= "text "/>
<img id= "rand_img " src= "VerifyCode.jsp " width= "75 " height= "20 " hspace= "6 " align= "absmiddle "/> <a href= "# " onclick= "javascript:document.getElementById( 'rand_img ').src= 'VerifyCode.jsp? '+Math.random(); "> 刷新图片 </a> </label>
<div class= "btn_box " align= "center "> <input name= "f_pw_sub " value= "登录 " type= "submit "/> <input type= "reset " name= "reset " value= "重置 "/> </div>
</form>
跳转的jsp
<%
java.text.SimpleDateFormat formatter = new java.text.SimpleDateFormat( "yyyy-MM-dd HH:mm:ss ");
java.util.Date currentTime = new java.util.Date();//得到当前系统时间
String str_date1 = formatter.format(currentTime); //将日期时间格式化
String str_date2 = currentTime.toString(); //将Date型日期时间转换成字符串形式
%>
<div id= "pass_left ">
<div id= "mem_info ">
<h5> 欢迎maxinlife <br/> <%=str_date1%>
<br/> </h5>
<dl>
<dd class= "headimg "> <img src= "images/defaultUser.jpg " alt= "头像 " height= "98 " width= "98 "/> </dd>
<dd> 昵 称: <span> maxin </span> </dd>
<dd> 生 日: <span> 1941年01月01日 </span> </dd> <dd class= "email "> <br/> 邮 箱: <a href= "mailto:dafa@m.com " target= "_blank "> dafa@m.com </a> </dd>
</dl>
上面都是主要部分的代码 求大人来帮帮忙 做毕业设计 急用
[解决办法]
发帖技巧
把错误提示贴出来,方便查错
[解决办法]
错误信息~~~
[解决办法]
lz检查:java.lang.NullPointerException
com.csu.struts.action.LoginAction.execute(LoginAction.java:59)
[解决办法]
if(request.getAttribute( "rand ").equals(loginForm.getString( "rand "))&&userServiceImp.isUser(username, password))
===>
String rand = request.getAttribute( "rand ");
if(null != rand && rand.equals(loginForm.getString( "rand "))&&userServiceImp.isUser(username, password))
...
request.getAttribute取出来的有可能是null的,调用null.equals当然报错,这是基本常识,还连发两贴来问
我的异常网推荐解决方案:Servlet.service() for servlet default threw exception,http://www.myexception.cn/eclipse/181756.html