struts1.2 actionform对象为空
刚接触struts1 ,做了一个简单的登陆例子,但是报
空指针错误!断点调试了下actionform对象为空!一直没找出错误,求解。
login.jsp页面代码
Java code
<div id="b">
<form action="login.do" method="post">
用户名:<input name="username" type="text" /><br />
密 码 :<input name="password" type="password" /><br />
<input name="ok" type="submit" value="" style="background-image:url(images/66.gif);height:30px;width:80px;border:0;"/>
</form>
</div>]
action类:
Java code
public class LoginAction extends Action {
@Override
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
// TODO Auto-generated method stub
userLogin u=(userLogin)form;
if(u.getUsername().equals("mandy")&&u.getPassword().equals("123"))
{
return mapping.findForward("index.jsp");
}
return super.execute(mapping, form, request, response);
}
actionform类:
public class userLogin extends ActionForm {
private String username;
private String password;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
struts-config.xml文件配置:
<struts-config>
<form-beans>
<form-bean name="userLogin" type="com.mycompany.struts"></form-bean>
</form-beans>
<action-mappings>
<action path="/login" type="com.mycompany.struts.LoginAction" name="userLogin">
<forward name="success" path="/index.jsp"></forward>
</action>
</action-mappings>
<message-resources parameter="com.mycompany.struts.ApplicationResources" />
</struts-config>
web.xml配置
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
<init-param>
<param-name>debug</param-name>
<param-value>3</param-value>
</init-param>
<init-param>
<param-name>detail</param-name>
<param-value>3</param-value>
</init-param>
<load-on-startup>0</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
------解决方案--------------------
<form-bean name="userLogin" type="