gpt4 book ai didi

java - 如何使用Jsp JSTL显示Spring模型?

转载 作者:太空宇宙 更新时间:2023-11-04 07:42:53 24 4
gpt4 key购买 nike

实际上在我的 spring 应用程序中有 User.jsp 并使用这个 Jsp 我显示详细信息。

在我的 UserProfileForm bean 中我正在编写

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

ProfessionalForm 还有另一种详细信息表格。

在我的 Controller 类中,我正在编写..

 @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";
}

还有我的 user.jsp 页面代码..

<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>

这是我的 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>

但是我的服务器控制台出现以下异常..

    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)

为什么出现此消息是 User.jsp 页面或 Professional.jsp 中的任何循环需要..

请帮助我..

编辑:

而不是 <jsp:include>我们正在使用...

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

还听到错误出现...

    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"%>

关于java - 如何使用Jsp JSTL显示Spring模型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15783835/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com