不了解JSP魔术是如何工作的

时间:2015-06-29 19:15:45

标签: java jsp servlet-3.0

我只是坚持使用以下代码。

以下是我的网络动态应用中的<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <section class="innovation"> <div class="categories-wrap"> <ul class="tabs"> <li class="tab-link" data-tab="tab-1"> <i class="sprite-call-black"></i> <h4>Pristine coverage</h4> <p>Enjoy your calls without interuptions like dropped calls, poor sound quality, and delayed video.</p> </li> <li class="tab-link" data-tab="tab-2"> <i class="sprite-call-black"></i> <h4>Chat messaging</h4> <p>Chat in real time with connections all around the world. </p> </li> <li class="tab-link" data-tab="tab-3"> <i class="sprite-call-black"></i> <h4>Video calling</h4> <p>WiFi paired with reliable cellular service is how we’ve got you covered in more places than ever before.</p> </li> <li class="tab-link" data-tab="tab-4"> <i class="sprite-call-black"></i> <h4>Photo share</h4> <p>WiFi paired with reliable cellular service is how we’ve got you covered in more places than ever before.</p> </li> </ul> </div> <div class="tabs-wrap"> <div id="tab-1" class="tab-content current"> <img src="" alt="Pristine Coverage"> </div> <div id="tab-2" class="tab-content"> <img src="" alt="Chat Messaging"> </div> <div id="tab-3" class="tab-content"> <img src="" alt="Video Calling"> </div> <div id="tab-4" class="tab-content"> <img src="" alt="Photo Share"> </div> </div> </section>

contextListener

我将package ua.nure.sanin.web.listener; import java.util.ResourceBundle; import javax.servlet.ServletContextEvent; import javax.servlet.ServletContextListener; import javax.servlet.annotation.WebListener; import org.apache.log4j.Logger; @WebListener public class ServletContextListenerImpl implements ServletContextListener { private static final Logger LOG = Logger.getLogger(System.class); @Override public void contextDestroyed(ServletContextEvent arg0) { LOG.info("contextDestroyed"); } @Override public void contextInitialized(ServletContextEvent sce) { LOG.info("contextInitialized"); ResourceBundle rb = ResourceBundle.getBundle("lang_en"); sce.getServletContext().setAttribute("lang", rb); } } 作为属性。

现在,我有一个运行良好的JSP页面。它包含这样的代码:

ResourceBundler

问题:

${lang.welcomeCoffee} 如何运作?

如果应该是:

${lang.welcomeCoffee}

1 个答案:

答案 0 :(得分:0)

实际上它不是

request.getServletContext().getAttribute("lang").getString("welcomeCoffee");

从EL的第3版开始,您可以通过多种方式自定义表达式语言处理。可能您的服务器知道如何阅读资源包。

有关概述,请参阅What's New With Expression Language In Java EE 7