我试图通过Java HttpServlet向JSP发送两个属性.问题是它们在我的JSP文件中都显示为0(数字).
这是我的RegisterDeveloper.java文件中的doGet方法:
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
// Fill up default attributes for the template
req.setAttribute("validation-error", false);
req.setAttribute("validation-error-message", "");
// Redirect to register page
req.getRequestDispatcher("/register.jsp").forward(req, resp);
}
Run Code Online (Sandbox Code Playgroud)
非常简单,当我单步执行属性时,会将请求添加到/register.jsp页面中.
这是register.jsp页面的问题部分:
<c:if test="${validation-error}">
<div id="validationError">
<span id="errorText">
${validation-error-message}
</span>
</div>
</c:if>
Run Code Online (Sandbox Code Playgroud)
由于某种原因,我添加到请求的属性都变为'0'.
浏览器中显示的错误是:
HTTP Status 500 - javax.el.ELException: Cannot convert 0 of type class java.lang.Long to class java.lang.Boolean
Run Code Online (Sandbox Code Playgroud)
我的web.xml与它相关:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>RServer</display-name>
<welcome-file-list>
<welcome-file>homepage.html</welcome-file>
</welcome-file-list>
<servlet-mapping>
<servlet-name>default</servlet-name> …Run Code Online (Sandbox Code Playgroud)