电脑软硬件应用网
当前位置: 电脑软硬件应用网 > 设计学院 > 网络编程 > javascript > 正文
Servlet、Jsp中的多国语言显示
Servlet、Jsp中的多国语言显示
2005-12-30 19:21:09  文/45IT收集   出处:电脑软硬件应用网   
coding) throws java.io.IOException{
if (urlenc == null) return;
StringTokenizer tok = new StringTokenizer(urlenc,"&");
try{
while (tok.hasMoreTokens()){
String aPair = tok.nextToken();
int pos = aPair.indexOf("=");
String name = null;
String value = null;
if(pos != -1){
name = decode(aPair.substring(0,pos),encoding);
value = decode(aPair.substring(pos+1),encoding);
}else{
name = aPair;
value = "";
}
if(pairs.containsKey(name)){
ArrayList values = (ArrayList)pairs.get(name);
values.add(value);
}else{
ArrayList values = new ArrayList();
values.add(value);
pairs.put(name,values);
}
}
}catch(Exception e){
throw new java.io.IOException(e.getMessage());
}
}
}
这个类的功能就是读取并保存form提交的信息,并实现常用的getParameter方法。
package com.hto.servlet;

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
/**
* Insert the type''s description here.
* Creation date: (2001-2-5 8:28:20)
* @author: 钱卫春
*/
public class UtfBaseServlet extends HttpServlet {
public static final String PARAMS_ATTR_NAME = "PARAMS_ATTR_NAME";
/**
* Process incoming HTTP GET requests 

* @param request Object that encapsulates the request to the servlet 
* @param response Object that encapsulates the response from the servlet
*/
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

performTask(request, response);

}
/**
* Process incoming HTTP POST requests 

* @param request Object that encapsulates the request to the servlet 
* @param response Object that encapsulates the response from the servlet
*/
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

performTask(request, response);

}
/**
* Insert the method''s description here.
* Creation date: (2001-2-5 8:52:43)
* @return int
* @param request javax.servlet.http.HttpServletRequest
* @param name java.lang.String
* @param required boolean
* @param defValue int
*/
public static java.sql.Date getDateParameter(HttpServletRequest request, String name, boolean required, java.sql.Date defValue) throws ServletException{
String value = getParameter(request,name,required,String.valueOf(defValue));
return java.sql.Date.valueOf(value);
}
/**
* Insert the method''s description here.
* Creation date: (2001-2-5 8:52:43)
* @return int
* @param request javax.servlet.http.HttpServletRequest
* @param name java.lang.String
* @param required boolean
* @param defValue int
*/
public static double getDoubleParameter(HttpServletRequest request, String name, boolean required, double defValue) throws ServletException{
String value = getParameter(request,name,required,String.valueOf(defValue));
return Double.parseDouble(value);
}
/**
* Insert the method''s description here.
* Creation date: (2001-2-5 8:52:43)
* @return int
* @param request javax.servlet.http.HttpServletRequest
* @param name java.lang.String
* @param required boolean
* @param defValue int
*/
public static float getFloatParameter(HttpServletRequest request, String name, boolean required, float defValue) throws ServletException{
String value = getParameter(request,name,required,String.valueOf(defValue));
return Float.parseFloat(value);
}
/**
* Insert the method''s description here.
* Creation date: (2001-2-5 8:52:43)
* @return int
* @param request javax.servlet.http.HttpServletRequest
* @param name java.lang.String
* @param required boolean
* @param defValue int
*/
public static int getIntParameter(HttpServletRequest request, String name, boolean required, int defValue) throws ServletException{
String value = getParameter(request,name,required,String.valueOf(defValue));
return Integer.parseInt(value);
}
/**
* Insert the method''s description here.
* Creation date: (2001-2-5 8:43:36)
* @return java.lang.String
* @param request javax.servlet.http.HttpServletRequest
* @param name java.lang.String
* @param required boolean
* @param defValue java.lang.String
*/
public static String getParameter(HttpServletRequest request, String name, boolean required, String defValue) throws ServletException{
if(request.getAttribute(UtfBaseServlet.PARAMS_ATTR_NAME) != null) {
UTF8ParameterReader params = (UTF8ParameterReader)request.getAttribute(UtfBaseServlet.PARAMS_ATTR_NAME);
if (params.getParameter(name) != null) return params.getParameter(name);
if (required) throw new ServletException("The Parameter "+name+" Required but not provided!");
else return defValue;
}else{
if (request.getParameter(name) != null) return request.getParameter(name);
if (required) throw new ServletException("The Parameter "+name+" Required but not provided!");
else return defValue;
}
}
/**
* Returns the servlet info string.
*/
public String getServletInfo() {

return super.getServletInfo();

}
/**
* Insert the method''s description here.
* Creation date: (2001-2-5 8:52:43)
* @return int
* @param request javax.servlet.http.HttpServletRequest
* @param name java.lang.String
* @param required boolean
* @param defValue int
*/
public static java.sql.Timestamp getTimestampParameter(HttpServletRequest request, String name, boolean required, java.sql.Timestamp defValue) throws ServletException{
String value = getParameter(request,name,required,String.valueOf(defValue));
return java.sql.Timestamp.valueOf(value);
}
/**
* Initializes the servlet.
*/
public void init() {
// insert code to initialize the servlet here

}
/**
* Process incoming requests for information

* @param request Object that encapsulates the request to the servlet 
* @param response Object that encapsulates the response from the servlet
*/
public void performTask(HttpServletRequest request, HttpServletResponse response) {

try

{
// Insert user code from here.

}
catch(Throwable theException)
{
// uncomment the following line when unexpected exceptions
// are occuring to aid in debugging the problem.
//theException.printStackTrace();
}
}
/**
* Insert the method''s description here.
* Creation date: (2001-2-5 8:31:54)
* @param request javax.servlet.ServletRequest
* @param response javax.servlet.ServletResponse
* @exception javax.servlet.ServletException The exception description.
* @exception java.io.IOException The exception description.
*/
public void service(ServletRequest request, ServletResponse response) throws javax.servlet.ServletException, java.io.IOException {
String content = request.getContentType();
if(content == null || content != null && content.toLowerCase().startsWith("applic

上一页  [1] [2] [3] 下一页

  • 上一篇文章:

  • 下一篇文章:
  • 最新热点 最新推荐 相关文章
    javascript实用技巧点滴(三)
    javascript实用技巧点滴(2)
    javascript实用技巧点滴(1)
    javascript教程 - 第一课 1.1
    用js制作完善的日,月组合下拉框
    利用JSP编程建立动态Web站点
    用PHP制作留言板
    PHP生成动态WAP页面
    PHP实现文件下载
    PHP4的session功能
    关于45IT | About 45IT | 联系方式 | 版权声明 | 网站导航 |

    Copyright © 2003-2011 45IT. All Rights Reserved 浙ICP备09049068号