代码:
package mypack;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspTagException;
import javax.servlet.jsp.tagext.TagSupport;
import javax.servlet.http.HttpSession;
import java.util.*;
import java.io.*;
public class MessageTag extends TagSupport
{
private String key=null;
public MessageTag() {
}
public String getKey(){
return this.key;
}
public void setKey(String key){
this.key=key;
}
// Method called when the closing hello tag is encountered
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 message11=null;
if(language!=null && language.equals( "Chinese ")){
message11=(String)ps_ch.get(key);
message11=new String(message.getBytes( "ISO-8859-1 "), "GB2312 ");
}
else
message11=(String)ps.get(key);
pageContext.getOut().print(message);
}
catch (Exception e) {
throw new JspTagException(e.getMessage());
}
// We want to return SKIP_BODY because this Tag does not support
// a Tag Body
return SKIP_BODY;
}