JSP请求中的属性变为0

Bit*_*ven 5 java jsp servlets request tomcat6

我试图通过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>
    <url-pattern>*.css</url-pattern>
    </servlet-mapping>

    <servlet>
        <servlet-name>RegisterDeveloper</servlet-name>
        <servlet-class>com.steven.RegisterDeveloper</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>RegisterDeveloper</servlet-name>
        <url-pattern>/register</url-pattern>
    </servlet-mapping>

</web-app>
Run Code Online (Sandbox Code Playgroud)

我正在使用Tomcat6.这一切看起来都很直接,我在其他页面上有非常相似的代码,所以我真的很难看到我错过了什么!

任何帮助,非常感谢.

我的/ WEB-INF/lib /文件夹中有javax.servlet.jsp.jstl-1.2.1.jar和javax.servlet.jsp.jstl-api-1.2.1.jar ..

Esa*_*ija 9

我用Google搜索规范

标识符被约束为Java标识符 - 例如,no - ,no /等.

validation-error不是Java的标识符,但对于减法运算validationerror.由于您尚未定义,因此null适用:

1.7.1二元运算符 - A {+, - ,*} B■如果A和B为空,则返回(长整数)0

所以我猜测试成了if( (Long)0 == true ).

试试吧 req.setAttribute("validationError", false); ${validationError}