问题描述
Errorsettingexpression'teacher.password'withvalue'[Ljava.lang.String;@1b6c184'ognl.OgnlException:targetisnullforsetProperty(null,"password",[Ljava.lang.String;@1b6c184)jsp:<%@pagecontentType="text/html;charset=utf-8"%><%@taglibprefix="s"uri="/struts-tags"%><%Stringpath=request.getContextPath();StringbasePath=request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";%><html><basehref="<%=basePath%>"><metahttp-equiv="pragma"content="no-cache"><metahttp-equiv="cache-control"content="no-cache"><metahttp-equiv="expires"content="0"><metahttp-equiv="keywords"content="keyword1,keyword2,keyword3"><metahttp-equiv="description"content="Thisismypage"><linkrel="stylesheet"href="style.css"type="text/css"/><body><ulid="saturday"><li><ahref="index.jsp">主页</a></li><li><ahref="http://sc.xueit.com">关于我们</a></li></ul><divalign="center"></div><div><center><formaction="teacherlogin"method="post"><table><tr><tdcolspan="2"><br></td></tr><tr><td>用户名:</td><td><inputtype="text"name="teacher.number"></td></tr><tr><td>密 码:</td><td><inputtype="password"name="teacher.password"></td></tr><tr><tdcolspan="3"><inputtype="submit"value="登陆"name="id"> <inputtype="reset"value="重置"name="password"> </td></tr></table></form></center></div></body></html>struts.xml<?xmlversion="1.0"encoding="UTF-8"?><!DOCTYPEstrutsPUBLIC"-//ApacheSoftwareFoundation//DTDStrutsConfiguration2.1//EN""http://struts.apache.org/dtds/struts-2.1.dtd"><struts><!--<constantname="struts.enable.DynamicMethodInvocation"value="false"/><constantname="struts.devMode"value="false"/><includefile="example.xml"/><packagename="default"namespace="/"extends="struts-default"><default-action-refname="index"/><actionname="index"><resulttype="redirectAction"><paramname="actionName">HelloWorld</param><paramname="namespace">/example</param></result></action></package>--><constantname="struts.devMode"value="false"/><packagename="default"namespace="/"extends="struts-default"><!--<actionname="Student_regist"class="com.neu.dwl.action.student.StudentAction"method="regist"><result>/index.jsp</result></action>--><actionname="*_*"class="com.neu.dwl.action.{1}Action"method="{2}"><resultname="success">/{1}_{2}_success.jsp</result><resultname="error">/{1}_{2}_failure.jsp</result><resultname="select">/Course_select.jsp</result><resultname="list">/StudentCourse_select_success.jsp</result><resultname="show">/StudentCourse_delete.jsp</result></action><actionname="teacherlogin"class="com.neu.dwl.action.teacherAction"method="login"><resultname="success">/teacher_login_success.jsp</result><resultname="error">/teacher_login_failure.jsp</result></action><!--<actionname="Course_list"class="com.neu.dwl.action.course.CourseAction"method="list"><result>/Course_select.jsp</result></action>--></package><!--Addpackageshere--></struts>bean:packagecom.neu.dwl.bean;publicclassteacher{privateIntegernumber;privateStringname;privateStringpassword;publicStringgetName(){returnname;}publicvoidsetName(Stringname){this.name=name;}publicStringgetPassword(){returnpassword;}publicvoidsetPassword(Stringpassword){this.password=password;}publicvoidsetNumber(Integernumber){this.number=number;}publicIntegergetNumber(){returnnumber;}}
解决方案
解决方案二:
看看是否是构造方法的问题,添加一个空的构造方法和所有属性的构造方法,另外看看action中传过来的参数有没有set,get
解决方案三:
在对应action中是否有teacher对象,并且要有get、set方法
解决方案四:
你Action中的Teacher对象有没有初始化~如果没有的话,一定要初始化,除非你把这件事交给spring~
解决方案五:
你的Action中应该维护一个Teacher对象Action中:privateTeacherteacher;
然后你的前台才能写teacher.name