2

I am developing a simple chat application in springs mvc but there is an error as

org.apache.jasper.JasperException: An exception occurred processing JSP page /WEB-INF/view/UserDetails.jsp at line 23

20: <c:out value="${chat.message}"/>
21: </c:forEach>
22: <form:form id="chat" modelAttribute="chatList" method="post" action="saveChat.html">
23: <form:input path="message"/>
24: <input type="submit" value="Send" />
25: </form:form>
26: <br>

and

org.springframework.beans.NotReadablePropertyException: Invalid property 'message' of bean class [java.util.ArrayList]: Bean property 'message' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter?
org.springframework.beans.BeanWrapperImpl.getPropertyValue(BeanWrapperImpl.java:665)
org.springframework.beans.BeanWrapperImpl.getPropertyValue(BeanWrapperImpl.java:657)
org.springframework.web.servlet.support.BindStatus.<init>(BindStatus.java:147)
org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getBindStatus(AbstractDataBoundFormElementTag.java:174)
org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getPropertyPath(AbstractDataBoundFormElementTag.java:194)
org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getName(AbstractDataBoundFormElementTag.java:160)
org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.autogenerateId(AbstractDataBoundFormElementTag.java:147)
org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.resolveId(AbstractDataBoundFormElementTag.java:138)
org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.writeDefaultAttributes(AbstractDataBoundFormElementTag.java:122)
org.springframework.web.servlet.tags.form.AbstractHtmlElementTag.writeDefaultAttributes(AbstractHtmlElementTag.java:409)
org.springframework.web.servlet.tags.form.InputTag.writeTagContent(InputTag.java:140)
org.springframework.web.servlet.tags.form.AbstractFormTag.doStartTagInternal(AbstractFormTag.java:102)
org.springframework.web.servlet.tags.RequestContextAwareTag.doStartTag(RequestContextAwareTag.java:79)
org.apache.jsp.WEB_002dINF.view.UserDetails_jsp._jspx_meth_form_005finput_005f0(UserDetails_jsp.java:250)
org.apache.jsp.WEB_002dINF.view.UserDetails_jsp._jspx_meth_form_005fform_005f0(UserDetails_jsp.java:215)
org.apache.jsp.WEB_002dINF.view.UserDetails_jsp._jspService(UserDetails_jsp.java:92)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:238)
org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:250)
org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1060)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:798)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:716)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:647)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:552)
javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)

My jsp file is

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!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=UTF-8">
<title>Being Java Guys | User Details</title>
</head>
<body>
<center>
<br><br><br><br><br><br>
<div style="color: teal;font-size: 30px">Group Chat</div>
<br><br>
<c:url var="userChat" value="saveChat.html"/>

<c:forEach items="${chat}" var="chat">
<c:out value="${chat.username}:"/>
<c:out value="${chat.message}"/>
</c:forEach>
<form:form id="chat" modelAttribute="chatList" method="post" action="saveChat.html">
<form:input path="message"/>
<input type="submit" value="Send" />
</form:form>
<br>
</center>
</body>
</html>

And relevant controller code is

@RequestMapping("/saveChat")
    public ModelAndView saveChat(@ModelAttribute("chatList") Chat chat,BindingResult result){
        userService.addChat(chat);
        return new ModelAndView("redirect:/userList");
    }

    @RequestMapping("/userList")
    public ModelAndView getUserList() {
        Map<String, Object> model = new HashMap<String, Object>();
        model.put("chat", userService.getChat());
        return new ModelAndView("UserDetails", model);

    }

The error is on the form input tag for sure since when I comment it this then it works fine.But why is that and what is the fix?

4

1 回答 1

1

这条线

return new ModelAndView("redirect:/userList");

导致 303 重定向状态代码作为响应发送。因此,在该请求期间添加的模型属性将不会在您的浏览器发出的下一个请求中可用。

考虑改用RedirectAttributes(闪存属性)。

于 2013-08-30T15:55:33.847 回答