我已经将ModelAndView对象设置为
modelv.addObject("document", document);
然后我已在JSP中导入了其他帮助程序
<%@ page import="com.publishing.util.DateUtil" %>
然后我正在尝试将文档字段用作这样的参数
<p><% DateUtil.TimestampToSpecificString(document.pub_date) %></p>
并且IDEA告诉我该文档无法解析
Stacktrace
jsp文件中的行[44]发生错误: [/WEB-INF/views/jsp/admin/document_card.jsp] document.pub_date无法 解析为类型41:
ОпубликРsвание 42:
43:
УдаленРs。
44:Датаивремяэл.РїСѓР±。 <% DateUtil.TimestampToSpecificString(document.pub_date); %>
45:
МестРsРsпубликРsоаниия СайС,
46:47:
Stacktrace:
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:103) org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:213) org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:473) org.apache.jasper.compiler.Compiler.compile(Compiler.java:392) org.apache.jasper.compiler.Compiler.compile(Compiler.java:362) org.apache.jasper.compiler.Compiler.compile(Compiler.java:346) org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:603) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:369) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:386) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:330) javax.servlet.http.HttpServlet.service(HttpServlet.java:741) org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:160) org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:303) org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1282) org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1037) org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:980) org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897) org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970) org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861) javax.servlet.http.HttpServlet.service(HttpServlet.java:634) org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846) javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
查看
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ page import="com.publishing.util.DateUtil" %>
<p><% DateUtil.TimestampToSpecificString(document.pub_date) %></p>
控制器
@RequestMapping(value = {"/search", "/search/"}, method = RequestMethod.GET)
public ModelAndView getSearch(ModelMap model,
HttpServletRequest request,
HttpServletResponse response,
HttpSession session) throws IOException,
ServletException {
Documents documents = new Documents(); //some fields there
modelv.addObject("documents", documents);
return modelv;
}
DateUtil
public class DateUtil {
public static String TimestampToSpecificString(Timestamp timestamp) {
//some code here...
}
}
答案 0 :(得分:0)
尝试使用request.getAttribute
方法获取在ModelView中设置的对象。
即
<% Documents document = (Documents)request.getAttribute("document"); %>
现在,由于在jsp页面中有可用的文档对象,您可以将其用于检索任何字段,在本例中为“ pub_date”。
<% DateUtil.TimestampToSpecificString(document.pub_date) %>
别忘了在jsp页面中导入Documents类。