Jquery 简单操作选项卡在 jsp 中不起作用

发布于 2024-11-05 18:59:09 字数 2005 浏览 0 评论 0原文

我正在尝试 jquery 选项卡,用户可以在其中添加选项卡和删除选项卡。我在这里找到了一个适合我需求的选项卡:

http://jqueryui.com/demos/tabs/#manipulation

我在开始的jsp页面中尝试了这个。当我运行应用程序时,它抛出一个异常,告诉:

服务器遇到内部错误()这阻止了它从满足这个请求。

异常

org.apache.jasper.JasperException: /Items.jsp(34,32) #{...} is not allowed in template  text
 org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:40)
org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:407)
org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:102)
org.apache.jasper.compiler.Validator$ValidateVisitor.visit(Validator.java:706)
org.apache.jasper.compiler.Node$ELExpression.accept(Node.java:958)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2361)
org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2411)
org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2417)
org.apache.jasper.compiler.Node$Root.accept(Node.java:495)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2361)
org.apache.jasper.compiler.Validator.validateExDirectives(Validator.java:1763)
org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:198)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:347)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:327)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:314)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:589)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:317)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

行 (34,32) 有

<a href='#{href}'>#{label}</a> <span class='ui-icon ui-icon-close'>Remove Tab</span>

但是当我将代码粘贴到 html 页面中时它运行得很好.. 为什么会有这种行为?谁能解释一下 谢谢:)

I was trying out jquery tabs where the user can add tabs and remove tabs.I found one suiting to my needs here:

http://jqueryui.com/demos/tabs/#manipulation

I tried this out in a jsp page in the starting.When I run the app it throws an exception telling:

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

exception

org.apache.jasper.JasperException: /Items.jsp(34,32) #{...} is not allowed in template  text
 org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:40)
org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:407)
org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:102)
org.apache.jasper.compiler.Validator$ValidateVisitor.visit(Validator.java:706)
org.apache.jasper.compiler.Node$ELExpression.accept(Node.java:958)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2361)
org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2411)
org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2417)
org.apache.jasper.compiler.Node$Root.accept(Node.java:495)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2361)
org.apache.jasper.compiler.Validator.validateExDirectives(Validator.java:1763)
org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:198)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:347)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:327)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:314)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:589)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:317)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

The line (34,32) has

<a href='#{href}'>#{label}</a> <span class='ui-icon ui-icon-close'>Remove Tab</span>

But when I pasted the code in an html page it runs just fine..
Why is this behaviour?? Can anyone explain
Thanks:)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

热风软妹 2024-11-12 18:59:09

问题是 JSP 使用表达式语言 (EL) 标记 ${} 来表示变量和类。虽然 #{} 不是 JSP EL 标记,但它是其后继 Facelets 的标记,并且会抛出错误,指出 JSP 中不允许这样做。您将必须使用其他方法来定义将在正则表达式替换中替换的变量部分。

而不是使用

<a href='#{href}'>#{label}</a> <span class='ui-icon ui-icon-close'>Remove Tab</span>

尝试类似的方法

<a href='~href~'>~label~</a> <span class='ui-icon ui-icon-close'>Remove Tab</span>

并将正则表达式替换行从

li = $( tabTemplate.replace( /#\{href\}/g, "#" + id ).replace( /#\{label\}/g, label ) ),

更改为

li = $( tabTemplate.replace( /~href~/g, "#" + id ).replace( /~label~/g, label ) ),

The problem is JSPs use expression-language (EL) tags ${} for variables and classes. While #{} isn't the JSP EL tag, it is the tag for it's successor, Facelets and it throws the error saying it isn't allowed in JSPs. You will have to use some other method to define your variable section that will be replaced in the regex replace.

Instead of using

<a href='#{href}'>#{label}</a> <span class='ui-icon ui-icon-close'>Remove Tab</span>

try something like

<a href='~href~'>~label~</a> <span class='ui-icon ui-icon-close'>Remove Tab</span>

and change the regex replace line from

li = $( tabTemplate.replace( /#\{href\}/g, "#" + id ).replace( /#\{label\}/g, label ) ),

to

li = $( tabTemplate.replace( /~href~/g, "#" + id ).replace( /~label~/g, label ) ),
近箐 2024-11-12 18:59:09

尝试用

<a href="#href">Give Label Here</a>

Try with

<a href="#href">Give Label Here</a>
一江春梦 2024-11-12 18:59:09
var $tabs = $('#tabs').tabs({
                    tabTemplate: '<li><a href="<%= "#" %>{href}"><%= "#" %>{label}</a> <a href="#" class="remove">x</a></li>',
                    add: function(event, ui) {
                        var tab_content = $tab_content_input.val() || 'Tab '+tab_counter+' content.';
                        $(ui.panel).append('<p>'+tab_content+'</p>');
                    }
                    });
var $tabs = $('#tabs').tabs({
                    tabTemplate: '<li><a href="<%= "#" %>{href}"><%= "#" %>{label}</a> <a href="#" class="remove">x</a></li>',
                    add: function(event, ui) {
                        var tab_content = $tab_content_input.val() || 'Tab '+tab_counter+' content.';
                        $(ui.panel).append('<p>'+tab_content+'</p>');
                    }
                    });
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文