Struts + spring + jooq集成 - 不调用struts动作

时间:2015-07-20 20:45:42

标签: spring jsp spring-mvc struts2 jooq

我正在编写一个struts + spring + jooq集成示例webapp。

我在db和jsp中有一个employee表,我可以在db中搜索一个员工并显示详细信息。问题是点击搜索没有任何反应。日志中没有错误,我在searchEmp操作中的print语句也没有在控制台上显示任何内容。你能否告诉我为什么没有调用struts动作方法?以下是详细信息

index.jsp文件

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib uri="/struts-tags" prefix="s"%>   
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"      "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Struts 2 Spring integration </title>
</head>
<body>
<s:form>
       <s:textfield label="Enter Id" name="eid" value="Enter employee name   here.."></s:textfield>
    <s:textfield label="Enter name" name="name" value="Enter name here..">      </s:textfield>
<s:textfield label="Enter city" name="city" value="Enter city here..">    </s:textfield>

    <s:submit value="Create new employee" action="saveEmpAction"/>
    <s:submit value="Update Employee" action="updateEmpAction"></s:submit>
    <s:submit value="Delete Employee" action="deleteEmpAction"></s:submit>
    <s:submit value="Search Employee" action="searchEmpAction"></s:submit>  
</s:form>

<s:property value="message"/>
<hr>
<table border="1">
    <s:iterator value="emps">
        <tr>
            <td><s:property value="eid"/></td>
            <td><s:property value="name"/></td>
            <td><s:property value="city"/></td>
        </tr>
    </s:iterator>
</table>

</body>
</html>

这是我的EmpAction.java类

package com.rewardsapp.action;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletContext;

import org.apache.struts2.ServletActionContext;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import test.generated.tables.pojos.Emp;

import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import com.opensymphony.xwork2.Preparable;
import com.rewardsapp.dao.EmpDao;

public class EmpAction extends ActionSupport implements ModelDriven<Emp>,   Preparable{


/**
 * 
 */
private static final long serialVersionUID = -2435427486571261741L;

Emp emp;
EmpDao empdao;
String message;
List<Emp> empList;

@Override
public void prepare() throws Exception {
    emp = new Emp();
    message = "";
    empList = new ArrayList<Emp>();
    ServletContext ctx = ServletActionContext.getServletContext();
    WebApplicationContext webappCtx = WebApplicationContextUtils.getWebApplicationContext(ctx);
    empdao = (EmpDao)webappCtx.getBean("empDao");
}

@Override
public Emp getModel() {
    return emp;
}

public String searchEmpAction() throws Exception {
    System.out.println("In search emp action");
    System.out.println("Search employee : " + emp.getName());

    Emp emp2 = empdao.getEmployee(emp.getId());
    empList.add(emp2);
    System.out.println("In search emp action");
    System.out.println("Searched employee : " + emp2.getName());
    return SUCCESS;
}

public Emp getEmp() {
    return emp;
}

public void setEmp(Emp emp) {
    this.emp = emp;
}

public EmpDao getEmpdao() {
    return empdao;
}

public void setEmpdao(EmpDao empdao) {
    this.empdao = empdao;
}

public String getMessage() {
    return message;
}

public void setMessage(String message) {
    this.message = message;
}

public List<Emp> getEmpList() {
    return empList;
}

public void setEmpList(List<Emp> empList) {
    this.empList = empList;
}
}

这是我的道教课程:

package com.rewardsapp.dao;

import org.jooq.DSLContext;
import org.springframework.dao.DataAccessException;

import com.rewardsapp.enums.ObjectType;
import com.rewardsapp.utils.NullObjectRegistry;

import static test.generated.tables.Emp.EMP;
import test.generated.tables.pojos.Emp;
import test.generated.tables.records.EmpRecord;

public class EmpDao {

/** The Constant NULL_CUSTOMER. */
private static final Emp NULL_EMP = (Emp)   NullObjectRegistry.getNullObject(ObjectType.EMP);

DSLContext dslContext;

public DSLContext getDslContext() {
    return dslContext;
}

public void setDslContext(DSLContext dslContext) {
    this.dslContext = dslContext;
}

public Emp getEmployee(int empId) throws Exception {
    try {
        EmpRecord empRecord = (EmpRecord) dslContext.select().from(EMP)
                .where((EMP.ID.equal(empId))).fetchAny();
        return (empRecord != null) ? empRecord.into(Emp.class) : NULL_EMP;
    } catch (DataAccessException e) {
        e.printStackTrace();
        /*throw new SystemException("Exception during getCustomerByCustomerType: " + customerType, e,
                SystemErrorCode.SQL_EXCEPTION_ERROR)*/;
        throw new Exception();
    }   
}
}

struts.xml中

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd">
<struts>
<package name="default" extends="struts-default" namespace="/">
<action name="searchEmpAction" class="com.rewardsapp.action.EmpAction" method="searchEmpAction">
<result name="success">index.jsp</result>
<result name="input">index.jsp</result>
<result name="error">index.jsp</result>
</action>
</package>
</struts>

0 个答案:

没有答案