简体   繁体   中英

How to display Spring model using Jsp JSTL?

Actually in my spring application have User.jsp and using this Jsp i'm display details.

In my UserProfileForm bean i'm writing

private List<ProfessionalForm> professionalDetails = new ArrayList<ProfessionalForm>();

And ProfessionalForm has another form for details.

In my controller class i'm writing..

 @RequestMapping(value = "user", method = RequestMethod.GET)
    public String user(Model model) throws Exception {
        UserProfileForm form = (UserProfileForm)FormType.USER_PROFILE.getNewInstance();

        model.addAttribute("USER_PROFILE", form);
        return "profile/user";
    }

And my user.jsp page code..

<form:form action="" modelAttribute="USER_PROFILE">
   <div class="answer">
    <c:forEach items="${USER_PROFILE.professionalDetails}" var="professionalForm">
        <jsp:include page="user/professional.jsp">
           <jsp:param value="${professionalForm}" name="PROFESSIONAL" />
        </jsp:include>
    </c:forEach>
   </div>
</form:form>

And this my professional.jsp..

<form:form action="profile/proffessional" modelAttribute="PROFESSIONAL">
<p>
  <label class="control_label">Postion:</label>
    <div class="controls">
        <form:input class="text_midem" path="positionName" />
    </div>
</p>
</form>

But i got follwoing Exception for my Server console..

    SEVERE: Servlet.service() for servlet [spring] in context with path [/EClass] threw exception [An exception occurred processing JSP page /WEB-INF/pages/profile/user.jsp at line 40

37:                         <div class="answer">
38:                             <c:forEach items="${USER_PROFILE.professionalDetails}"
39:                                 var="professionalForm">
40:                                 <jsp:include page="user/professional.jsp">
41:                                     <jsp:param value="${professionalForm}" name="PROFESSIONAL" />
42:                                 </jsp:include>
43:                             </c:forEach>


Stacktrace:] with root cause
java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'PROFESSIONAL' available as request attribute
    at org.springframework.web.servlet.support.BindStatus.<init>(BindStatus.java:141)

Why this message coming is their any Loop Required for in User.jsp page or Professional.jsp..

Please help me..

EDIT:

Instead of <jsp:include> we are using ...

<%@include file="user/professional.jsp"%>

Hear also error coming...

    SEVERE: Servlet.service() for servlet [spring] in context with path [/EClass] threw exception [An exception occurred processing JSP page /WEB-INF/pages/profile/user/professional.jsp at line 16

13:                                 <p>
14:                                     <label class="control_label">Postion:</label>
15:                                 <div class="controls">
16:                                   <form:input class="text_midem" path="positionName" />
17:                                 </div>
18:                                 </p>
19:                                 <p>


Stacktrace:] with root cause
java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'PROFESSIONAL' available as request attribute

使用<%@ include%>代替jsp:include

<%@include file="user/professional.jsp"%>
......
<jsp:include page="user/professional.jsp">
           <jsp:param value="${professionalForm}" name="PROFESSIONAL" />
        </jsp:include>
.......

The above code sends request parameter named PROFESSIONAL to the professional.jsp page and not request attribute . While the below code looks for request attribute

....
<form:form action="profile/proffessional" modelAttribute="PROFESSIONAL">
....

So you need to set the value as request attribute perhaps.

Try the below code

.......

<form:form action="" modelAttribute="USER_PROFILE">
   <div class="answer">
    <c:forEach items="${USER_PROFILE.professionalDetails}" var="professionalForm">
        <c:set var="PROFESSIONAL" scope="request" value="${professionalForm}">
        <jsp:include page="user/professional.jsp">           
        </jsp:include>
    </c:forEach>
   </div>
</form:form>
........

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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