這里只是寫到配置方法:
第一步:LoginAction:
package com.inspur.actions;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
struts2框架,import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
import com.inspur.forms.*;
public class LoginAction extends DispatchAction {
?//響應登錄
??public ActionForward login(ActionMapping mapping, ActionForm form,
????HttpServletRequest request, HttpServletResponse response)
????throws Exception {
???System.out.println("******通過新的方式響應請求***********");
???/*
???
???EmployeeForm employeeForm=(EmployeeForm)form;
???//構建一個Employee對象
???Employee e=new Employee();
???e.setId(employeeForm.getId());
???e.setName(employeeForm.getName());
???e.setLeader(employeeForm.getLeader());
???e.setMid("111111");
???eif.addEmployee(e);
???request.getSession().setAttribute("adder", e);
???*/
???return mapping.findForward("ok");
??}
??
}
第二步:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//
DTD Struts Configuration 1.3//EN" "http://struts.apache.org/dtds/struts-config_1_3.dtd">
<struts-config>
?<form-beans>
?<form-bean name="userForm" type="com.inspur.forms.UserForm" />
?</form-beans>
?<action-mappings>
?<action path="/login" parameter="flag" name="userForm" type="com.inspur.actions.LoginAction">
?<forward name="ok" path="/WEB-INF/welcome.jsp"/>
?<forward name="err" path="/WEB-INF/login.jsp"/>?
?</action>
?</action-mappings>
?<!-- 配置代理請求處理 DelegatingRequestProcessor ,它的用戶是
?<controller>
? ?<set-property property="processorClass" value="org.springframework.web.struts.DelegatingRequestProcessor"/>
?</controller>
? -->
</struts-config>