The following example configures values in the properties file and reads them in the view file (JSP). This helps in providing the internationalization support to your web application.
application.properties
helloworldMsg=Hello There. Welcome to my Struts Application
Adding message-resources to struts-config.xml
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN" "http://jakarta.apache.org/struts/dtds/struts-config_1_2.dtd"> <struts-config> <!-- Using Global Forwards to forward to the desired view for Home Page --> <global-forwards> <forward name="HelloWorld" path="/WEB-INF/jsp/HelloWorld.jsp" /> </global-forwards> <!-- Contains the URL Mapping --> <action-mappings> <action path="/helloworld" type="org.mybusiness.strutstutorial.actions.HelloWorldAction" /> </action-mappings> <message-resources parameter="application" /> </struts-config>
/WEB-INF/jsp/HelloWorld.jsp
Struts Framework provides its own view tags that can be used to easily develop the front end pages.
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Hello World</title> </head> <body bgcolor="#ffe"> <h2>Hello World. Welcome to my Struts based web application</h2> <h4>The following message is displayed using struts bean:message tag</h4> <bean:message key="helloworldMsg" /> </body> </html>
With the above changes to your web application, your new helloworld web page should be able to read data from the properties file and display it to the user.
No comments:
Post a Comment