如何在Struts中从JSP重定向到Action类



JSP FIle--->

<html:form method="post" action="/createEmployee">
    <p><font color="red">*</font>First Name</p>
    <p><html:text property="firstName" /></p>
    <p><font color="red">*</font>Last Name</p>
    <p><html:text property="lastName" /></p>
    <p><font color="red">*</font>Birth Date</p>
    <p><html:text property="birthDate" value="" /></p>
    <p><font color="red">*</font>Salary</p>
    <p><html:text property="salary" /></p>
    <p><font color="red">*</font>Organization</p>
    <p><html:text property="organization" /></p>
    <p><input type="submit" value="Save" name="submitBtn" /></p>
    <p><input type="reset" value="Cancel" name="cancelBtn" /></p>
</html:form>

行动类别--->

public ActionForward excute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception
{
    System.out.println(request.getParameter("msg"));
    EmployeeForm employeeForm = (EmployeeForm)form;
    OrganizationServiceImpl organizationService = new OrganizationServiceImpl();
    long organizationId = organizationService.getOrganizationByName(employeeForm.getOrganization());
    employeeForm.setOrganization_id(organizationId);
    EmployeeServiceImpl employeeService = new EmployeeServiceImpl();
    long employeeId = employeeService.creatEmployee(employeeForm);
    request.setAttribute("employeeId", employeeId);
    return mapping.findForward("createEmployee");
}

我想知道我在jsp文件中给出的Action路径是否正确??我的操作类在"com.hr.action"

您需要将您的操作映射到struts-config.xml中的URL。检查struts-config.xml以获得正确的映射

最新更新