0

我正在做一个简单的表单spring,稍后将与 ejb 连接。

所以我的jsp是(我的jsp中有spring库):

<form:form commandName="TestDTO" method="POST">
    <form:input path="test" maxlength="20"
            id="test" />
    <input type="button"
        onClick="javascript:validarCamposConsulta('consultaTest.htm')"
        value="Consultar" class="boton" />
</form:form>

我的控制器是这样的(我在包声明后导入了spring):

@Controller
public class TestController {
    protected final Log logger = LogFactory.getLog(getClass());
private final String testDTO = "TestDTO";

@RequestMapping("/consulta.htm")
public ModelAndView preload(HttpServletRequest request,
        HttpServletResponse response) throws ServletException, IOException {
    String forward = "/consulta/CONSULTA"; 

    /*try {
        configuradorIDA.setupIsbanDataAccess();
    } catch (Exception e) {

        System.out.println("Error al inicializar IDA: " + e.getMessage());
    }*/
    return new ModelAndView(forward);
}

@RequestMapping("/consultaTest.htm")
public final String consultaTest(
        @ModelAttribute(testDTO)
        final TestDTO testdto,
        final BindingResult result,
        final ModelMap model,
        final HttpServletRequest request,
        final HttpServletResponse response) {
    String forward = "/consulta/CONSULTA";
    testdto.getTest();
    model.addAttribute(testDTO, testdto);
    return forward;
}

}

我在 websphere 7 上运行它,所以当我运行它时,我得到下一个错误:

    Error 500: org.springframework.web.util.NestedServletException: 
Request processing failed; nested exception is 
java.lang.IllegalStateException: 
Neither BindingResult nor plain target object 
for bean name 'TestDTO' available as request attribute

有谁知道发生了什么?

提前致谢。

4

1 回答 1

0

好的,看来我的方法预加载公司应该是

@RequestMapping("/consulta.htm")
    public ModelAndView preload(@ModelAttribute(testDTO)
    final TestDTO testdto, HttpServletRequest request,
            HttpServletResponse response) throws ServletException, IOException {

这解决了它。

于 2012-12-20T19:49:36.570 回答