login.jsp-->
LoginAction.java--->
public class LoginAction extends Action {
//我们需要重新编写一个方法 :execute会被自动调用,有点类似servlet里面的service方法
@Override
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
//form转成对应的UserForm对象
UserForm userForm=(UserForm)form;
System.out.println("用户名-->"+userForm.getUsername());
System.out.println("密码-->"+userForm.getPassword());
request.setAttribute("username",userForm.getUsername());
if("123".equals(userForm.getPassword())){
return mapping.findForward("ok");
}else{
return mapping.findForward("err");
}
}
}
UserForm.java--->
package com.cb.forms;
//这是一个用户表单,用于填充数据
import org.apache.struts.action.ActionForm;
//继承一个超类ActionForm
public class UserForm extends ActionForm {
//定义属性【这里有一个规范,就是我们定义属性名字的时候,
//应该和jsp页面空间名称一样】
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--->
web.xml----->