Java Struts2 国际化中英切换页面

struts2国际化,实现登录表单中英文切换,在地址栏中增加参数request_locale=en_US即可正确切换到英文登录页面。

注意(在web.xml中有三种配置)
(1) /* 捕捉所有请求
(2) / 捕捉所有除 jsp页面之外的请求
(3) *.action 捕捉所有的action请求

login.jsp

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>


     
    Document
	
  
  
   
  	
      
        

main.jsp(登录成功后跳转的页面,在此不做登录处理)

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>


  
    Main Document
  
  
    main
  

web.xml

  
  
     
    
    login.jsp  
    
    
    struts2  
      
        org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter  
      
    
    
    struts2  
    /*  
   

struts.xml




	
	  
	
      
          
            /main.jsp
          
          
            /login.jsp  
          
      
    


LoginAction.java

package top.k10000;
import com.opensymphony.xwork2.ActionSupport;

public class LoginAction extends ActionSupport {  
    private static final long serialVersionUID = 5282197184219501014L;  
    private User user;  
  
    public User getUser() {  
        return user;  
    }  
    public void setUser(User user) {  
        this.user = user;  
    }
    
    public String login() throws Exception {
    	return SUCCESS;
    }
}

ChangeLang.java

package top.k10000;
import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionSupport;
public class ChangeLang extends ActionSupport {  
    private static final long serialVersionUID = 3791113563988999604L;  
    @Override  
    public String execute() throws Exception {  
        return Action.SUCCESS;  
    }  
}

User.java

package top.k10000;

public class User {
	 private String name;  
	 private String pass;
	 
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getPass() {
		return pass;
	}
	public void setPass(String pass) {
		this.pass = pass;
	}
	 
}

资源文件:

Java Struts2 国际化中英切换页面_第1张图片


Java Struts2 国际化中英切换页面_第2张图片

Java Struts2 国际化中英切换页面_第3张图片

Java Struts2 国际化中英切换页面_第4张图片

你可能感兴趣的:(#,SSH古董框架,Java)