Java Tutorial/JSP/Resource Bundle — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Текущая версия на 05:07, 1 июня 2010
Include Page in another Directory
index.jsp
<html>
<body>
Let"s include some content: <i><%@include file="included.jsp" %></i>
<P>
<%@include file="includeFiles/banner.html" %>
</body>
</html>
Load Resource Bundle
<source lang="java">
<%--
Copyright (c) 2002 by Phil Hanna All rights reserved. You may study, use, modify, and distribute this software for any purpose provided that this copyright notice appears in all copies. This software is provided without warranty either expressed or implied.
--%> <%@ page session="false"
import="java.io.*, java.net.*, java.util.*" %>
<html> <head> <title>Using Cookies to Store Preferences</title> <style><%= STYLESHEET %></style> </head> <body>
<%= getLanguageBar(request) %> |
<%-- Localized greeting --%>
<%= getGreeting(request) %>
<%-- Store language preference in a persistent cookie --%> <% storeLanguagePreferenceCookie(request, response); %>
</body> </html> <%!
// =========================================== // Helper methods included here for // clarity. A better choice would be // to put them in beans or a servlet. // =========================================== /** * The CSS stylesheet */ private static final String STYLESHEET = "h1 { font-size: 130%; }\n" + ".LB {\n" + " background-color: #005A9C;\n" + " color: #FFFFFF;\n" + " font-size: 90%;\n" + " font-weight: bold;\n" + " padding: 0.5em;\n" + " text-align: right;\n" + " word-spacing: 1em;\n" + "}\n" + ".LB a:link, .LB a:active, .LB a:visited {\n" + " text-decoration: none;\n" + " color: #FFFFFF;\n" + "}\n"; /** * Creates the language preference bar */ private String getLanguageBar (HttpServletRequest request) throws IOException { String thisURL = request.getRequestURL().toString(); StringBuffer sb = new StringBuffer(); appendLink(sb, thisURL, Locale.ENGLISH); appendLink(sb, thisURL, Locale.GERMAN); appendLink(sb, thisURL, Locale.FRENCH); appendLink(sb, thisURL, Locale.ITALIAN); String languageBar = sb.toString(); return languageBar; } /** * Helper method to create hyperlinks */ private void appendLink (StringBuffer sb, String thisURL, Locale locale) throws UnsupportedEncodingException { if (sb.length() > 0) sb.append(" "); String language = locale.getLanguage(); sb.append("