简体   繁体   English

为什么我不能在自定义标签中使用JSP EL?

[英]Why can't I use JSP EL in my custom tag?

When I use the ${} for expression language outside of my tag, it works with a number or operations and anything. 当我在标签之外使用$ {}作为表达语言时,它可以与数字,运算符或其他任何东西一起使用。 But whenever I put it inside my custom tag as a value, an error shows up. 但是,每当我将其作为值放置在自定义标签中时,就会出现错误。 I checked similar questions in the internet and tried all their solutions but none of them worked. 我在互联网上检查了类似的问题,并尝试了所有解决方案,但没有一个起作用。 Btw, I'm just following a tutorial in tutorialspoint.com and I believe I did everything correctly. 顺便说一句,我只是在跟随tutorialspoint.com中的一个教程,我相信我做的一切都正确。

This is the error that shows up: 这是显示的错误:

type Exception report

message /WEB-INF/view/itr.jsp (line: 72, column: 7) According to TLD or attribute directive in tag file, attribute value does not accept any expressions

description The server encountered an internal error that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: /WEB-INF/view/itr.jsp (line: 72, column: 7) According to TLD or attribute directive in tag file, attribute value does not accept any expressions
    org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:41)
    org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:275)
    org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:107)
    org.apache.jasper.compiler.Validator$ValidateVisitor.checkXmlAttributes(Validator.java:1241)
    org.apache.jasper.compiler.Validator$ValidateVisitor.visit(Validator.java:879)
    org.apache.jasper.compiler.Node$CustomTag.accept(Node.java:1536)
    org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2376)
    org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2428)
    org.apache.jasper.compiler.Validator$ValidateVisitor.visit(Validator.java:898)
    org.apache.jasper.compiler.Node$CustomTag.accept(Node.java:1536)
    org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2376)
    org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2428)
    org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2434)
    org.apache.jasper.compiler.Node$Root.accept(Node.java:464)
    org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2376)
    org.apache.jasper.compiler.Validator.validateExDirectives(Validator.java:1853)
    org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:217)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:356)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:336)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:323)
    org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:585)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:363)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    org.openmrs.web.filter.JspClassLoaderFilter.doFilter(JspClassLoaderFilter.java:47)
    org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:101)
    org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:101)
    org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:168)
    org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:303)
    org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1228)
    org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1011)
    org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:955)
    org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:877)
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:966)
    org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:857)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
    org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    org.openmrs.module.web.filter.ForcePasswordChangeFilter.doFilter(ForcePasswordChangeFilter.java:60)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    org.openmrs.web.filter.GZIPFilter.doFilterInternal(GZIPFilter.java:64)
    org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    org.openmrs.module.web.filter.ModuleFilterChain.doFilter(ModuleFilterChain.java:72)
    org.openmrs.module.owa.filter.OwaFilter.doFilter(OwaFilter.java:57)
    org.openmrs.module.web.filter.ModuleFilterChain.doFilter(ModuleFilterChain.java:70)
    org.openmrs.module.web.filter.ModuleFilter.doFilter(ModuleFilter.java:54)
    org.openmrs.web.filter.OpenmrsFilter.doFilterInternal(OpenmrsFilter.java:108)
    org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    org.springframework.orm.hibernate4.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:150)
    org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    org.openmrs.web.filter.StartupFilter.doFilter(StartupFilter.java:105)
    org.openmrs.web.filter.StartupFilter.doFilter(StartupFilter.java:105)
    org.openmrs.web.filter.StartupFilter.doFilter(StartupFilter.java:105)
    org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
    org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)

These are my code: 这些是我的代码:

HelloTag.java HelloTag.java

package org.openmrs.web.taglib;

import javax.servlet.jsp.tagext.*;
import javax.servlet.jsp.*;
import java.io.*;

public class HelloTag extends SimpleTagSupport {

    private double value;

    public void setValue(double val) {
        this.value = val;
    }

    StringWriter sw = new StringWriter();

    public void doTag() throws JspException, IOException {
        if (value != 0) {
            /* Use message from attribute */
            JspWriter out = getJspContext().getOut();
            out.println( value );
        }
        else {
            /* use message from the body */
            getJspBody().invoke(sw);
            getJspContext().getOut().println(sw.toString());
        }
    }
}

custom.tld custom.tld

<taglib>
  <tlib-version>1.0</tlib-version>
  <jsp-version>1.2</jsp-version>
  <short-name>Example TLD</short-name>
  <uri>http://java.sun.com/jsp/jstl/core_rt</uri>
  <tag>
    <name>Hello</name>
    <tag-class>org.openmrs.web.taglib.HelloTag</tag-class>
    <body-content>scriptless</body-content>
    <attribute>
       <name>value</name>
    </attribute>
  </tag>
</taglib>

itr.jsp itr.jsp

<%@ include file="/WEB-INF/view/module/chitscore/template/include.jsp" %>
<%@ page isELIgnored="false" %>

<h1>Individual Treatment Record</h1>

<h3>Anthropometric Data</h3>
<c:set var="OPENMRS_VIEWING_PATIENT_ID" scope="request" value="${patient.patientId}"/>
<form:form action="anthropometricdata.form" method="POST" modelAttribute="anthropometricdata">
    <table>
        <form:input path="patientId" type="hidden" value="${patient.patientId}"/>
        <tr>
            <td>Height</td>
            <td><form:input path="height" /></td>
        </tr>
        <tr>
            <td>Weight</td>
            <td><form:input path="weight" /></td>
        </tr>
        <tr>
            <td>Body Mass Index</td>
            <td></td>
        </tr>
        <tr>
            <td>Waist Circumference</td>
            <td><form:input path="waistCircumference" /></td>
        </tr>
        <tr>
            <td>Hip Circumference</td>
            <td><form:input path="hipCircumference" /></td>
        </tr>
        <tr>
            <td>Waist-Hip Ratio</td>
            <td></td>
        </tr>
        <tr>
            <td>Head Circumference</td>
            <td><form:input path="headCircumference" /></td>
        </tr>
        <tr>
            <td>Chest Circumference</td>
            <td><form:input path="chestCircumference" /></td>
        </tr>
        <tr>
            <td colspan="2">
                <input type="submit" name="action" value="Save" />
                <input type="submit" name="action" value="Cancel" />
            </td>
        </tr>
    </table>
</form:form>
<br>
<table border="1">
    <th>Height</th>
    <th>Weight</th>
    <th>Body Mass Index</th>
    <th>Waist Circumference</th>
    <th>Hip Circumference</th>
    <th>Waist-Hip Ratio</th>
    <th>Head Circumference</th>
    <th>Chest Circumference</th>
    <th>test</th>
    <c:forEach items="${anthropometricdataList}" var="anthropometricdata">
        <tr>
            <td>${anthropometricdata.height}</td>
            <td>${anthropometricdata.weight}</td>
            <td>${anthropometricdata.bmi}</td>
            <td>${anthropometricdata.waistCircumference}</td>
            <td>${anthropometricdata.hipCircumference}</td>
            <td>${anthropometricdata.waistHipRatio}</td>
            <td>${anthropometricdata.headCircumference}</td>
            <td>${anthropometricdata.chestCircumference}</td>
            <td><ex:Hello value="${ anthropometricdata.weight }"/>${1 + 2 }</td>
        </tr>
    </c:forEach>
</table>

<%@ include file="/WEB-INF/view/module/chitscore/template/footer.jsp" %>

According to Java EE Tutorial , you have to set rtexprvalue to true for your tag. 根据Java EE教程 ,您必须将标签的rtexprvalue设置为true Ie

<attribute>
   <name>value</name>
   <rtexprvalue>true</rtexprvalue>
</attribute>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么我的jsp中不能使用核心taglib? - Why can't I use core taglib in my jsp? 我可以使用 JSF 1.2 和 JSP 2.1 在 ac:forEach 标记上的统一 EL 表达式中使用哈希表吗? - Can I use a Hashtable in a unified EL expression on a c:forEach tag using JSF 1.2 with JSP 2.1? 为什么不能在此JSP自定义标记中将scriptlet属性传输到JSTL? - Why can I not transfer a scriptlet attribute to JSTL in this JSP custom tag? 为什么我不能使用<jsp:getproperty>没有<jsp:usebean> ?</jsp:usebean></jsp:getproperty> - Why I can't use <jsp:getProperty> without <jsp:useBean>? 如何使用JSP EL insinde标记属性 - How to use JSP EL insinde tag attribute 为什么我在jsp中看不到我的$ {token}? - Why can't i see my ${token} in my jsp? 当我使用spring mvc和jsp时,为什么我的参数不能传递值? - when I use spring mvc and jsp, why my argument can't transfer the value? 在我的Spring 3.2 MVC应用程序中,为什么登录后我的JSP EL表达式不会被评估? - In my Spring 3.2 MVC application, why aren't my JSP EL expressions being evaluated after login? 如何在我的自定义标签库中使用 JSP 页面模板 - How to use JSP page templates in my custom tag library 为什么我为自定义jsp EL函数得到JasperException PWC:6299? - Why am I getting a JasperException PWC:6299 for a custom jsp EL function?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM