Internationalization Using Automatic
Approach
index.jsp
======
<a
href="login.htm">Click here for greeting message</a>
web.xml
======
<?xml
version="1.0" encoding="UTF-8"?>
<web-app
version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>*.htm</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>
</web-app>
dispatcher-servlet.xml
==============
<?xml
version='1.0' encoding='UTF-8' ?>
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-4.0.xsd">
<context:component-scan base-package="myspring"
/>
<bean id="messageSource"
class="org.springframework.context.support.ResourceBundleMessageSource"
p:basename="message" />
</beans>
success.jsp
=======
<%
out.println("Successful
Login...");
%>
login.jsp
======
<%@page
contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib
uri="http://www.springframework.org/tags" prefix="spring"
%>
<%@taglib
uri="http://www.springframework.org/tags/form"
prefix="form" %>
<!DOCTYPE
html>
<html>
<body>
<form:form method="POST"
commandName="user" >
<spring:message
code="inp.username" /><form:input path="name" />
<br />
<spring:message
code="inp.pwd" /><form:input path="pwd" /> <br
/>
<input type="submit"
value="<spring:message code="inp.submit" /> " />
</form:form>
</body>
</html>
failure.jsp
======
Login
Failed.....
MyController.java
===========
package
myspring;
import
org.springframework.stereotype.Controller;
import
org.springframework.ui.ModelMap;
import
org.springframework.web.bind.annotation.ModelAttribute;
import
org.springframework.web.bind.annotation.RequestMapping;
import
org.springframework.web.bind.annotation.RequestMethod;
@Controller
@RequestMapping("/login.htm")
public
class MyController {
@RequestMapping(method = RequestMethod.GET)
public String showForm(ModelMap m){
User user = new User();
m.addAttribute("user",user);
return "/WEB-INF/jsp/login.jsp";
}
@RequestMapping(method =
RequestMethod.POST)
public String
onSubmit(@ModelAttribute("user") User user){
System.out.println("Inside of
onSubmit...");
if(user.getName().equals("admin") &&
user.getPwd().equals("admin")){
System.out.println("Inside of
onSubmit of if...");
return
"/WEB-INF/jsp/success.jsp";
}
return
"/WEB-INF/jsp/failure.jsp";
}
}
User.java
======
package
myspring;
public
class User {
private String name;
private String pwd;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPwd() {
return pwd;
}
public void setPwd(String pwd) {
this.pwd = pwd;
}
}
message.properties
=============
inp.username
= User Name
inp.pwd
= Pass Word
inp.submit
= Login
message_te_IN.properties
=================
inp.username
= వాడుకరి పేరు
inp.pwd
= పాస్ వర్డ్
inp.submit
= లాగిన్
message_hi_IN.properties
=================
inp.username
= उपयोगकर्ता नाम H
inp.pwd
= पासवर्ड H
inp.submit
= Login H
No comments:
Post a Comment