English 中文(简体)
如果属性无效,我能否在共同财产法的标签中放弃对共同财产法的例外?
原标题:Can I throw exception with JSTL in a custom JSP tag when an attribute is invalid?

I m Making some JSP tag. 我将一个参数带给标签。

守则就是这样:

<%@ attribute name="type" require="true" %>
<c:choose>
    <c:when test="${type eq  even }">
        <c:set var="remainder" value="0" />
    </c:when>
    <c:when test="${type eq  odd }">
        <c:set var="remainder" value="1" />
    </c:when>
    <c:otherwise>
        <%-- Want to throw exception!! --%>
    </c:otherwise>
</c:choose>

如果我错失价值,我想提出一个例外。 我在寻找这个主题时,刚刚发现rel=“nofollow”>。 Can t 我在《司法独立法》中放弃了正常的例外。

最佳回答

只是立即注意到这一问题。

谁会“通知”? 这种例外只能由集装箱控制,将产生大约“500台内部服务器“Error”页(或你界定的一些习俗错误页)。

如果你真想的话,你可以确定一个只履行“新观念”的习俗标签,然后使用你习惯的标签,如:<代码><mytaglib:reportError/>,因为标准核心标签不考虑给任何人一个例外。

问题回答

I would just use a custom EL function or tag which systematically throws an exception, or displays a big red div with the error message, or both

${myFn:illegalState("the type must be odd or even but it is " ${type})}

我在此假定,你的目标是让开发商知道他们不正当地利用你的习俗。 由于在其他答复中已经提到过,你希望以不同的方式处理用户输入错误,因为在联合项目上留下的错误很可能(视配置而定)最终将用户送到应用错误的网页。

如果你能够把tag的tag头手编成法典,那么,pec在TLD中就包含一些可以做到的任择内容。

  1. The spec defines the validator element which takes a class implementing javax.servlet.jsp.tagext.TagLibraryValidator. In practice this is somewhat complicated to use as it offers a bunch of flexibility.
  2. The spec also defines tei-class which takes a class extending TagExtraInfo. As the JavaDoc notes:

    Extra Tag Information for a Custom Tag; this class is mentioned in the Tag Library Descriptor file (TLD). This class must be used:

    • if the tag defines any scripting variables
    • if the tag wants to provide translation-time validation of the tagattributes.

视共同未来方案版本而定,您需要超越isValid(validate(>)方法,处理验证开发商提供的变量。

The Apache taglibs use these for validating some of their tags: (https://github.com/javaee/jstl-api/blob/master/impl/src/main/java/org/apache/taglibs/standard/tei/ImportTEI.java)

    public boolean isValid(TagData us) {
        if (Util.isSpecified(us, VAR) && Util.isSpecified(us, VAR_READER))
            return false;

        return true;
    }

OR 如果您正在使用联合执行文件P 2.0,执行<编码>validate<>code>,则其复杂程度不大,因为它能够退回一个<代码>的阿雷娜>。 玻璃鱼的例子有:

    public ValidationMessage[] validate(TagData data) {
        ValidationMessage[] vms = null;
        TagLibraryInfo[] infos =
            getTagInfo().getTagLibrary().getTagLibraryInfos();
        if (infos.length != 1) {
            vms = new ValidationMessage[1];
            vms[0] = new ValidationMessage(null, "Wrong number of tsglibs");
        }
        return vms;
    }




相关问题
handling exceptions IN Action Filters

Is there a better way to handle exceptions that occur inside an Action Filter itself in ASP .NET MVC? There re 2 ways I can think of at the moment. Using a try catch and setting the HTTP Status ...

既可捕获,又可举出例外。

我有一种办法,可以进入亚洲开发银行,因此,我国的亚行在多瑙河航道中的所有 st子都位于一个试捕区。 它正在追捕Kexception

Cross compiler exception handling - Can it be done safely?

I am doing some maintenance on a C++ windows dll library that is required to work with different VC++ compilers (as I don’t want to address different mangling schemes). I have already eliminated any ...

File Handling Issue

I am developing a tool in c#, at one instance I start writing into a xml file continuously using my tool,when i suddenly restart my machine the particular xml file gets corrupted, what is the reason ...

Watch a memory location/install data breakpoint from code?

We have a memory overwrite problem. At some point, during the course of our program, a memory location is being overwritten and causing our program to crash. the problem happens only in release mode. ...

Unit Test for Exceptions Message

Is there a simple (Attribute-driven) way to have the following test fail on the message of the exception. [TestMethod()] [ExpectedException(typeof(ArgumentException))] public void ExceptionTestTest() ...

热门标签