简体   繁体   English

Spring MVC中的表单发布后无法在视图中获得价值

[英]Unable to get value in view after form post in Spring mvc

This is my ControllerClass 这是我的ControllerClass

public class ScheduleClassController extends SimpleFormController {

public ScheduleClassController() {
    setCommandClass(ScheduleClass.class);
    setCommandName("scheduleClass");
}

protected ModelAndView onSubmit(HttpServletRequest request,
        HttpServletResponse response, Object command) throws Exception {

    ScheduleClass wiziqClass = (ScheduleClass) command;
    System.out.println(wiziqClass);
    return new ModelAndView("classdetail", "ScheduleClass", wiziqClass);

}
}

This is my springapp-servelet.xml 这是我的springapp-servelet.xml

http://www.springframework.org/schema/beans/spring-beans-2.0.xsd"> http://www.springframework.org/schema/beans/spring-beans-2.0.xsd“>

<bean id="viewResolver"
    class="org.springframework.web.servlet.view.UrlBasedViewResolver">
    <property name="viewClass"
        value="org.springframework.web.servlet.view.JstlView" />
    <!-- <property name="prefix" value="/WEB-INF/jsp/" /> -->
    <property name="suffix" value=".jsp" />
    <property name="order" value="10" />
</bean>

<bean name="/index.htm" class="org.sakaiproject.wiziq.tool.HelloWorldController">
    <property name="sakaiProxy" ref="org.sakaiproject.wiziq.logic.SakaiProxy" />
</bean>

<bean name="/schedule.htm" class="org.sakaiproject.wiziq.tool.ScheduleClassController">
    <property name="formView" value="schedule" />
    <property name="successView" value="classdetail" />
</bean>

This is my classdetail.jsp 这是我的classdetail.jsp

<jsp:directive.include file="/templates/includes.jsp" />
<jsp:directive.include file="/templates/header.jsp" />

hello there
${wiziqClass.name}

<jsp:directive.include file="/templates/footer.jsp" />

After submitting the form i land on this view but not getting the wiziqClass.name here I have made Model and added getter and setter there. 提交表单后,我进入了该视图,但未在此处获取wiziqClass.name,我制作了Model并在其中添加了getter和setter。

What i'm doing wrong? 我做错了什么? Not able to figure out. 无法弄清楚。

Please change any one of place . 请改变任何一个地方。 Don't change in two places. 不要在两个地方更改。

 protected ModelAndView onSubmit(HttpServletRequest request,
      HttpServletResponse response, Object command) throws Exception {

      ScheduleClass wiziqClass = (ScheduleClass) command;
      System.out.println(wiziqClass);
      return new ModelAndView("classdetail", "wiziqClass", wiziqClass);
}

or 要么

 ${ScheduleClass.name}

According to your code the name of the attribute is 'ScheduleClass' and not 'wiziqClass'... So change the expression in your jsp 根据您的代码,属性的名称为'ScheduleClass'而不是'wiziqClass'...因此,请更改jsp中的表达式

protected ModelAndView onSubmit(HttpServletRequest request,
    HttpServletResponse response, Object command) throws Exception {

  ScheduleClass wiziqClass = (ScheduleClass) command;
  System.out.println(wiziqClass);
  return new ModelAndView("classdetail", "ScheduleClass", wiziqClass);
}

${ScheduleClass.name} $ {ScheduleClass.name}

Got it working the main problem is that the onSubmit was not working i mistakenly removed BindException errors from 得到它的主要问题是onSubmit无法正常工作,我错误地从中删除了BindException错误
onSubmit(HttpServletRequest request, HttpServletResponse response, Object command,BindException errors) and that was causing the error second error was what M.Dienum told onSubmit(HttpServletRequest request, HttpServletResponse response, Object command,BindException errors) ,导致错误的第二个错误是M.Dienum所说的

Thanks to both of you 感谢你们俩

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM