struts初学者的问题
做一个struts的logindemo,代码如下;
LoginAction类
public class LoginAction extends Action {
@Override
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
LoginForm loginForm = (LoginForm)form;
if(loginForm.getUsername().equals("shenlichao")){
return mapping.findForward("loginSuccess");
}else{
return mapping.findForward("loginFailure");
}
}
}
loginform类
public class LoginForm extends ActionForm {
public String username = null;
public String password = null;
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;
}
}
web.xml配置
<welcome-file-list>
<welcome-file>Login.jsp</welcome-file>
</welcome-file-list>
<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>
<load-on-startup>0</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
struts-config.xml配置
<struts-config>
<form-beans>
<form-bean name="loginFrom" type="demo.LoginForm"></form-bean>
</form-beans>
<action-mappings>
<action path="/login" type="demo.LoginAction" name="loginForm">
<forward name="loginSuccess" path="/LoginSuccess.jsp"></forward>
<forward name="loginFailure" path="/LoginFailure.jsp"></forward>
</action>
</action-mappings>
</struts-config>
到了登陆界面之后输入shenlichao,输入用户名shenlichao点登陆,就出现HTTP Status 500错误,
The server encountered an internal error () that prevented it from fulfilling this request.不是很明白为什么 希望大家给点指导
------解决方案--------------------你页面上的代码呢 看下页面上的代码有没有错
public String username = null;
public String password = null;
这两个变量名 和你页面上的 是不是一致
------解决方案--------------------+1
------解决方案--------------------
<form-bean name="loginFrom" type="demo.LoginForm"></form-bean>
</form-beans>
<action-mappings>
<action path="/login" type="demo.LoginAction" name="loginForm">
名称写错了
我的异常网推荐解决方案:The server encountered an internal error () that prevented it from fulfilling this request.,http://www.myexception.cn/java-web/317.html