Ludzie pragną czasami się rozstawać, żeby móc tęsknić, czekać i cieszyć się z powrotem.
You could look into the
official docu and would probably be better off, though.
Our web.xml must define an action Servlet and the links to the ltd-files. Just copy one
web.xml from the Struts sources and remove everything else.
Empty struts-config.xml
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.0//EN"
"http://jakarta.apache.org/struts/dtds/struts-config_1_0.dtd">
<struts-config></struts-config>
4
Chapter 4. Second Try: Struts For Internationalisation
web.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
"http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">
<web-app>
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<init-param>
<param-name>application</param-name>
<param-value>ApplicationResources</param-value>
</init-param>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
<init-param>
<param-name>debug</param-name>
<param-value>2</param-value>
</init-param>
<init-param>
<param-name>detail</param-name>
<param-value>2</param-value>
</init-param>
<init-param>
<param-name>validate</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
<!-- Standard Action Servlet Mapping -->
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>invoker</servlet-name>
<url-pattern>/servlet/*</url-pattern>
</servlet-mapping>
<!-- The Welcome File List -->
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
<!-- Struts Tag Library Descriptor -->
<taglib>
<taglib-uri>
/WEB-INF/struts-bean.tld
</taglib-uri>
<taglib-location>
/WEB-INF/struts-bean.tld
</taglib-location>
</taglib>
<taglib>
<taglib-uri>
/WEB-INF/struts-html.tld
</taglib-uri>
<taglib-location>
/WEB-INF/struts-html.tld
</taglib-location>
</taglib>
<taglib>
<taglib-uri>
/WEB-INF/struts-logic.tld
</taglib-uri>
<taglib-location>
/WEB-INF/struts-logic.tld
</taglib-location>
</taglib>
<taglib>
<taglib-uri>
/WEB-INF/struts-template.tld
</taglib-uri>
<taglib-location>
/WEB-INF/struts-template.tld
</taglib-location>
</taglib>
</web-app>
5
Chapter 4. Second Try: Struts For Internationalisation
Okay, lets start with something really easy. We will display the title of the page in dif-
ferent languages, depending on the preference of the user.
Create a file called 'ApplicationResources.properties' in the classes dirctory.
Open it and enter the line: 'index.title=Struts Tutorial' into it
Create another file called 'ApplicationResources_de.properties' (de for Deutschland (Germany)) and enter
'index.title=Struts Einführung'
Edit the BookView.jsp and change the head to:
BookView.jsp: Introducing Internationalization
<%@ page language="java" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld"
prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld"
prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<html:html locale="true">
<head>
<html:base/>
<title>
<bean:message key="index.title"/>
</title>
</head>
<body>
<h2>BookView</h2>
</body>
</html:html>
Import the needed TLD files.
Here is our language dependend value.
Don't forget to close this tag in the right format.
Figure 4.2. Displaying the German title element
Now you have to reload the strutsShop context, otherwise the propertie files will not be
evaluated.
6
Chapter 4. Second Try: Struts For Internationalisation
Figure 4.3. Reloading a Context With Tomcat 4.x
You have to do this everytime you change something in the language files.
Note
For Tomcat 3.x, you have to restart the server, as it doesn't have the manager
functionallity.