修改action

来源:互联网 发布:excel编程入门教程 编辑:程序博客网 时间:2024/05/22 03:28

更改源文件MyAction.java

package strutsdemo;

import org.apache.struts.action.*;
import javax.servlet.http.*;

public class MyAction extends Action {
public ActionForward execute(ActionMapping actionMapping, ActionForm actionForm, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) {
/**@todo: complete the business logic here, this is just a skeleton.*/
MyActionForm myActionForm = (MyActionForm) actionForm;
throw new java.lang.UnsupportedOperationException("Method perform() not yet implemented.");
}
}

更改为:

package strutsdemo;

import org.apache.struts.action.*;
import javax.servlet.http.*;

public class MyAction extends Action {
public ActionForward execute(ActionMapping actionMapping, ActionForm actionForm, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) {
/**@todo: complete the business logic here, this is just a skeleton.*/
MyActionForm myActionForm = (MyActionForm) actionForm;
//获得由login.jsp 传来的用户名
String username=myActionForm.getUserName();
//获得由login.jsp 传来的密码
String pass= myActionForm.getPassWord();
String target;//定义转向
//执行逻辑部分
if (username.equalsIgnoreCase("JYD") && pass.equals("12345")) {
target="ok"; //转到ok.jsp
//可通过 HttpServletRequest 传值
httpServletRequest.setAttribute("status","登陆成功");
}
else
{
target="error"; //转到 error.jsp
//可通过 HttpServletRequest 传值
httpServletRequest.setAttribute("status","登陆失败");
}

return actionMapping.findForward(target);


// throw new java.lang.UnsupportedOperationException("Method perform() not yet implemented.");
}
}

 

原创粉丝点击