2017-04-06 31 views
0

當我使用$ {}作爲表達式語言以外的標記時,它可以處理數字或任何操作。但是,無論何時將其放入自定義標記中作爲值,都會顯示錯誤。我在互聯網上查了類似的問題,嘗試了所有的解決方案,但都沒有成功。順便說一句,我只是按照tutorialspoint.com中的教程,我相信我做的一切都正確。爲什麼我不能在自定義標籤中使用JSP EL?

這是顯示了錯誤:

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

回答

0

Java EE Tutorial,你必須設置rtexprvaluetrue您的標籤。即

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

我剛纔在打開這個之前找到了答案。我很抱歉在詢問之前看起來不夠好。儘管非常感謝! –

相關問題