jsp中传输中文参数(java ee5 tutorial)

主要需要注意:
<%
        request.setCharacterEncoding(
"ISO-8859-1");
        String loc
=getStr(request.getParameter("locale"));
%>
<%! 
    
public String getStr(String str){
        
try{
            String t 
= new String(str.getBytes("ISO-8859-1"),"UTF-8");
            
return t;
        }
catch(Exception e){}
        
return null;
    }

%>  


整个例子全部为:
<%@page contentType="text/html;charset=UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@taglib uri="/WEB-INF/functions" prefix="f" %>

<%
    
public String getStr(String str){
        try{
            
String t = new String(str.getBytes("ISO-8859-1"),"UTF-8");
            return t;
        }catch(Exception e){}
        return 
null;
    }
%> 
<!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=UTF-8">
        
<title>JSP Page</title>
    
</head>
    
<body>
       
        
<h1>JSP Page</h1>
        
<jsp:plugin type="applet" code="DigitalClock.class" codebase="/JSPs" jreversion="1.4" align="center" height="25" width="300"
            nspluginurl
="http://java.sun.com/j2se/1.4/download.html"
            iepluginurl
="http://java.sun.com/j2se/1.4/download.html" >
            
<jsp:params>
                
<jsp:param name="language" value="<%=request.getLocale().getLanguage()%>" />
                
<jsp:param name="country" value="<%=request.getLocale().getCountry()%>" />
                
<jsp:param name="bgcolor" value="FFFFFF" />
                
<jsp:param name="fgcolor" value="CC0066" />
            
</jsp:params>
            
<jsp:fallback>
                
<p>Unable to start plugin.</p>
            
</jsp:fallback>
        
</jsp:plugin>
       
<%
        request.setCharacterEncoding(
"ISO-8859-1");
        
String loc=getStr(request.getParameter("locale"));
%>
       
        
<jsp:useBean id="locales" scope="application" class="mypkg.MyLocales"/>
        
<form name="localeForm" action="index.jsp" method="post">                 
            
<p/>
            
<c:set var="selectedLocaleString" value="<%=loc%>" />
            
<c:set var="selectedFlag" value="${!empty selectedLocaleString}" />
            
<b>Locale:</b>
            
<select name=locale>
                
<c:forEach var="localeString" items="${locales.localeNames}" >
                    
<c:choose>
                        
<c:when test="${selectedFlag}">
                            
<c:choose>
                                
<c:when test="${f:equals(selectedLocaleString,localeString)}" >
                                    
<option selected>${localeString}</option>
                                
</c:when>
                                
<c:otherwise>
                                    
<option>${localeString}</option>
                                
</c:otherwise>
                            
</c:choose>
                        
</c:when>
                        
<c:otherwise>
                            
<option>${localeString}</option>
                        
</c:otherwise>
                    
</c:choose>
                
</c:forEach>
            
</select>
            
<input type="submit" name="Submit" value="Get Date">
        
</form>
        
<p/>
        
<c:if test="${selectedFlag}" >
            
<jsp:setProperty name="locales" property="selectedLocaleString" value="${selectedLocaleString}" />
            
<jsp:useBean id="date" class="mypkg.MyDate"/>
            
<jsp:setProperty name="date" property="locale" value="${locales.selectedLocale}"/>
            
<b>Date: </b>${date.date}
        
</c:if>

   
    
</body>
</html>


注意一个问题:applet的代码不能放在WEB-INF中
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值