簡體   English   中英

為什么我不能在自定義標簽中使用JSP EL?

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

當我在標簽之外使用$ {}作為表達語言時,它可以與數字,運算符或其他任何東西一起使用。 但是,每當我將其作為值放置在自定義標簽中時,就會出現錯誤。 我在互聯網上檢查了類似的問題,並嘗試了所有解決方案,但沒有一個起作用。 順便說一句,我只是在跟隨tutorialspoint.com中的一個教程,我相信我做的一切都正確。

這是顯示的錯誤:

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)

這些是我的代碼:

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

<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

<%@ 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" %>

根據Java EE教程 ,您必須將標簽的rtexprvalue設置為true

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM