9:25 am - Saturday August 23, 2014

struts 1x i18n internationalization with example program In Eclipse

Project Structure:

 JAR Files:

 

TLD Files:

 

Following is the list of required JAR files to be added in Java Class Path of your project. Download displaytag JAR files from 

JAR FILES + TLD FILES 

WelcomeAction.java: 

package com.candid;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

public class WelcomeAction extends org.apache.struts.action.Action {

	private final static String SUCCESS = "success";

	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {

		return mapping.findForward("success");

	}
}

WelcomeForm.java:

package com.candid;

public class WelcomeForm extends org.apache.struts.action.ActionForm {
	private static final long serialVersionUID = 1L;

	private String name;

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

}

ApplicationResource.properties:

# -- standard errors --
errors.header=<UL>
errors.prefix=<LI>
errors.suffix=</LI>
errors.footer=</UL>
# -- validator --
errors.invalid={0} is invalid.
errors.maxlength={0} can not be greater than {1} characters.
errors.minlength={0} can not be less than {1} characters.
errors.range={0} is not in the range {1} through {2}.
errors.required={0} is required.
errors.byte={0} must be an byte.
errors.date={0} is not a date.
errors.double={0} must be an double.
errors.float={0} must be an float.
errors.integer={0} must be an integer.
errors.long={0} must be an long.
errors.short={0} must be an short.
errors.creditcard={0} is not a valid credit card number.
errors.email={0} is an invalid e-mail address.

label.enteryourname = Enter your Name
label.submit = submit
label.welcome = welcome

ApplicationResource_de.properties:

# To change this template, choose Tools | Templates
# and open the template in the editor.

label.enteryourname = Geben Sie Ihren Namen
label.submit = einreichen
label.welcome = willkommen

ApplicationResource_it.properties:

# To change this template, choose Tools | Templates
# and open the template in the editor.

label.enteryourname = inserisci il tuo nome
label.submit = presentare
label.welcome = benvenuto

web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
	<servlet>
		<servlet-name>action</servlet-name>
		<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
		<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>
		<load-on-startup>2</load-on-startup>
	</servlet>
	<servlet-mapping>
		<servlet-name>action</servlet-name>
		<url-pattern>*.do</url-pattern>
	</servlet-mapping>
	<session-config>
		<session-timeout>
			30
        </session-timeout>
	</session-config>
	<welcome-file-list>
		<welcome-file>index.jsp</welcome-file>
	</welcome-file-list>
	<jsp-config>
		<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-nested.tld</taglib-uri>
			<taglib-location>/WEB-INF/struts-nested.tld</taglib-location>
		</taglib>
		<taglib>
			<taglib-uri>/WEB-INF/struts-tiles.tld</taglib-uri>
			<taglib-location>/WEB-INF/struts-tiles.tld</taglib-location>
		</taglib>
	</jsp-config>
</web-app>

success.jsp:


<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>
<%@taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>welcome</title>
</head>
<body bgcolor="pink">
<h3><bean:message key="label.welcome" /></h3>
&nbsp;&nbsp;
<bean:write name="WelcomeForm" property="name" />

</body>
</html>

welcome.jsp:




<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>
<%@taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Welcome</title>
</head>
<body bgcolor="pink">
<html:form action="/WelcomeAction">
	<bean:message key="label.enteryourname" />
	<html:text property="name" size="30"></html:text>
	<html:submit>
		<bean:message key="label.submit" />
	</html:submit>
</html:form>
</body>
</html>

OUTPUT:

DOWNLOAD+SOURCE CODE                                                                                                                                                       BACK

Filed in: Z-AStruts Codes

No comments yet.

Leave a Reply

Social Widgets powered by AB-WebLog.com.