亚洲免费在线-亚洲免费在线播放-亚洲免费在线观看-亚洲免费在线观看视频-亚洲免费在线看-亚洲免费在线视频

WelcometohelloApp

Engl" />

帶有自定義標簽庫的中英文頁面

系統 2730 0
一個用于選擇不同語言的JSP頁面
    

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

<html>
  <head>

    
    <title>welcome to hello jsp</title>


  </head>
  
  <body>
    <p><font size=7>Welcome to helloApp</font></p>
    <p><a href="WelcomeLogin.jsp?language=English">English Page</a></p>
    <p><a href="WelcomeLogin.jsp?language=Chinese">Chinese Page</a></p>
     </body>
</html>


  


帶有自定義標簽庫的中英文頁面


分別為中文和英文的Properties的文件
    
hello.title=helloapp
hello.hi=Nice to meet you
login.title=helloapp
login.user=Username
login.password=Password
login.submit=Submit

  
    
hello.title=helloapp
hello.hi=你好
login.title=helloapp的登錄頁面
login.user=用戶名
login.password= 密碼
login.submit=登錄

  



用于加載中英文靜態文本的Servelt類

    
package Tag1;

import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Properties;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class LoginServlet extends HttpServlet {

	

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
         init();
         PrintWriter pw =response.getWriter();
         pw.println("The resouce file is reloaded");
		
	}

	
	public void init() throws ServletException {
		 Properties ps =new Properties();
		 Properties ps_ch=new Properties();
		 
		 ServletContext context =getServletContext();
		 
		 InputStream in=context.getResourceAsStream("/WEB-INF/message.properties");
		 InputStream in_ch=context.getResourceAsStream("/WEB-INF/message_ch.properties");
		 try {
			ps.load(in);
			ps_ch.load(in_ch);
			in.close();
			in_ch.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		context.setAttribute("ps", ps);
		context.setAttribute("ps_ch", ps_ch);
		 
	}

}


  


一個標簽處理類

    
package Tag1;

import java.util.Properties;

import javax.servlet.http.HttpSession;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;

public class MessageTag extends TagSupport {
    private String key =null;

	public String getKey() {
		return key;
	}

	public void setKey(String key) {
		this.key = key;
	}

	@Override
	public int doEndTag() throws JspException {
		try{
	    Properties ps =(Properties)pageContext.getAttribute("ps", pageContext.APPLICATION_SCOPE);
		
		Properties ps_ch=(Properties)pageContext.getAttribute("ps_ch", pageContext.APPLICATION_SCOPE);
		
		HttpSession session=pageContext.getSession();
		
		String language=(String)session.getAttribute("language");
		
		String message=null;
		if(language!=null&&language.equals("Chinese")){
			message =(String)ps_ch.get(key);
			message=new String(message.getBytes("ISO-8859-1"),"UTF-8");
		}else{
			message=(String)ps.get(key);
		}
		pageContext.getOut().println(message);
		
	
		}catch(Exception e){
			e.printStackTrace();
		}
		return EVAL_PAGE;
	}
     
    
}



  



一個標簽庫
     
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE taglib PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN"
                        "http://java.sun.com/dtd/web-jsptaglibrary_1_2.dtd">
<taglib>
 <tlib-version>1.0</tlib-version>
 <jsp-version>1.2</jsp-version>
 <short-name>MyTag</short-name>
 <uri>/MyTag</uri>
<tag>
   <name>MyTag</name>
   <tag-class>Tag1.MessageTag</tag-class>
   <body-content>empty</body-content>
   <attribute>
      <name>key</name>
      <required>true</required>
   </attribute>
 </tag>
</taglib>

  


根據選擇 顯示不同語言的JSP頁面
    
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="/WEB-INF/MyTag.tld" prefix="cc"%>
<html>
   <%  
      String language=request.getParameter("language");	
      if(language==null)
    	  language="English";
      session.setAttribute("language",language);
     
   %>
  <head>
   <title><cc:MyTag key="login.title"/></title>
   </head>
  <body>
    <br>
    <form name="LoginForm" method="post" action="Welcomout.jsp">
        <cc:MyTag key="login.user"/>:<br>
        
        <input type="text" name="username"><br>
        <cc:MyTag key="login.password"/>:<br>
        <input type="password" name="password"/><br>
        <input type="submit" value="<cc:MyTag key="login.submit"/>"/><br/>
    </form>
  </body>
</html>


  


web.xml配置信息:
    
  <jsp-config>
  <taglib>
  <taglib-uri>/WEB-INF/MyTag.tld</taglib-uri>
  <taglib-location>/WEB-INF/MyTag.tld</taglib-location>
</taglib>
</jsp-config>

  

帶有自定義標簽庫的中英文頁面


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】元

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 快射视频欧美 | 99久久精品视香蕉蕉er热资源 | 国产精品久久久久久久牛牛 | 久草久草久草 | 精品一区二区三区亚洲 | 亚洲成人免费在线观看 | 国产亚洲久久 | 欧美成人啪啪看片 | 久久国产精品久久精 | 女人一级毛片免费观看 | 99九九精品 | 国产精品日韩在线观看 | 狠狠色丁香婷婷综合久久来 | 亚洲一欧洲中文字幕在线 | 国产精品久久久久久久久久一区 | 国产成人午夜 | 日韩午夜在线视频 | 国产农村一一级特黄毛片 | 亚洲国产综合自在线另类 | 天天色天天干天天射 | 卡通动漫亚洲综合 | 亚洲精品人成在线观看 | 久久夜色tv网站免费影院 | 成人午夜在线观看 | 久久亚洲影院 | 亚洲国产综合精品中文字幕 | 天天在线天天综合网色 | 91视频国产高清 | 久久天天躁狠狠躁夜夜中文字幕 | 伊人97| 九九99九九精彩网站 | 国产精品18久久久久网站 | 亚洲一区二区三区影院 | 暗香影院午夜国产精品 | 欧美一级视频免费 | 性一交一乱一视频免费看 | 色在线视频观看 | 一本久久a久久精品亚洲 | 久久首页 | 亚洲一级免费毛片 | 成人亚洲精品7777 |