- 浏览: 976886 次
- 性别:
- 来自: 上海
文章分类
最新评论
-
Mr.Cheney:
去掉 UUID字符串中的“-” 直接replaceAll(&q ...
JAVA生成全局唯一ID 使用 java.util.UUID -
呜哩喵:
楼主nice
java中的时间操作 -
zxs6587:
Thinking inJava我读着好像说要建立基类对象啊!请 ...
创建子类的对象时也要创建其所有父类的对象? -
just_Word:
getFullYear
date.getyear -
JamesQian:
我觉得楼上的synchronized(this),notify ...
notify() wait()
ParamUtils这个类,觉得以后做项目时可以把做成一个单独的组件使用,解决了request.getParameter()时只能取出String的问题。
/**
* $RCSfile: ParamUtils.java,v $
* $Revision: 1.6 $
* $Date: 2001/07/31 05:38:18 $
*
* Copyright (C) 1999-2001 CoolServlets, Inc. All rights reserved.
*
* This software is the proprietary information of CoolServlets, Inc.
* Use is subject to license terms.
*/
package com.jivesoftware.forum.util;
import javax.servlet.http.*;
/**
* This class assists skin writers in getting parameters.
*/
public class ParamUtils {
/**
* Gets a parameter as a string.
* @param request The HttpServletRequest object, known as "request" in a
* JSP page.
* @param name The name of the parameter you want to get
* @return The value of the parameter or null if the parameter was not
* found or if the parameter is a zero-length string.
*/
public static String getParameter(HttpServletRequest request, String name) {
return getParameter(request, name, false);
}
/**
* Gets a parameter as a string.
* @param request The HttpServletRequest object, known as "request" in a
* JSP page.
* @param name The name of the parameter you want to get
* @param emptyStringsOK Return the parameter values even if it is an empty string.
* @return The value of the parameter or null if the parameter was not
* found.
*/
public static String getParameter(HttpServletRequest request,
String name, boolean emptyStringsOK)
{
String temp = request.getParameter(name);
if (temp != null) {
if (temp.equals("") && !emptyStringsOK) {
return null;
}
else {
return temp;
}
}
else {
return null;
}
}
/**
* Gets a parameter as a boolean.
* @param request The HttpServletRequest object, known as "request" in a
* JSP page.
* @param name The name of the parameter you want to get
* @return True if the value of the parameter was "true", false otherwise.
*/
public static boolean getBooleanParameter(HttpServletRequest request,
String name)
{
return getBooleanParameter(request, name, false);
}
/**
* Gets a parameter as a boolean.
* @param request The HttpServletRequest object, known as "request" in a
* JSP page.
* @param name The name of the parameter you want to get
* @return True if the value of the parameter was "true", false otherwise.
*/
public static boolean getBooleanParameter(HttpServletRequest request,
String name, boolean defaultVal)
{
String temp = request.getParameter(name);
if ("true".equals(temp) || "on".equals(temp)) {
return true;
}
else if ("false".equals(temp) || "off".equals(temp)) {
return false;
}
else {
return defaultVal;
}
}
/**
* Gets a parameter as an int.
* @param request The HttpServletRequest object, known as "request" in a
* JSP page.
* @param name The name of the parameter you want to get
* @return The int value of the parameter specified or the default value if
* the parameter is not found.
*/
public static int getIntParameter(HttpServletRequest request,
String name, int defaultNum)
{
String temp = request.getParameter(name);
if(temp != null && !temp.equals("")) {
int num = defaultNum;
try {
num = Integer.parseInt(temp);
}
catch (Exception ignored) {}
return num;
}
else {
return defaultNum;
}
}
/**
* Gets a list of int parameters.
* @param request The HttpServletRequest object, known as "request" in a
* JSP page.
* @param name The name of the parameter you want to get
* @param defaultNum The default value of a parameter, if the parameter
* can't be converted into an int.
*/
public static int[] getIntParameters(HttpServletRequest request,
String name, int defaultNum)
{
String[] paramValues = request.getParameterValues(name);
if (paramValues == null) {
return null;
}
if (paramValues.length < 1) {
return new int[0];
}
int[] values = new int[paramValues.length];
for (int i=0; i<paramValues.length; i++) {
try {
values[i] = Integer.parseInt(paramValues[i]);
}
catch (Exception e) {
values[i] = defaultNum;
}
}
return values;
}
/**
* Gets a parameter as a double.
* @param request The HttpServletRequest object, known as "request" in a
* JSP page.
* @param name The name of the parameter you want to get
* @return The double value of the parameter specified or the default value
* if the parameter is not found.
*/
public static double getDoubleParameter(HttpServletRequest request,
String name, double defaultNum)
{
String temp = request.getParameter(name);
if(temp != null && !temp.equals("")) {
double num = defaultNum;
try {
num = Double.parseDouble(temp);
}
catch (Exception ignored) {}
return num;
}
else {
return defaultNum;
}
}
/**
* Gets a parameter as a long.
* @param request The HttpServletRequest object, known as "request" in a
* JSP page.
* @param name The name of the parameter you want to get
* @return The long value of the parameter specified or the default value if
* the parameter is not found.
*/
public static long getLongParameter(HttpServletRequest request,
String name, long defaultNum)
{
String temp = request.getParameter(name);
if (temp != null && !temp.equals("")) {
long num = defaultNum;
try {
num = Long.parseLong(temp);
}
catch (Exception ignored) {}
return num;
}
else {
return defaultNum;
}
}
/**
* Gets a list of long parameters.
* @param request The HttpServletRequest object, known as "request" in a
* JSP page.
* @param name The name of the parameter you want to get
* @param defaultNum The default value of a parameter, if the parameter
* can't be converted into a long.
*/
public static long[] getLongParameters(HttpServletRequest request,
String name, long defaultNum)
{
String[] paramValues = request.getParameterValues(name);
if (paramValues == null) {
return null;
}
if (paramValues.length < 1) {
return new long[0];
}
long[] values = new long[paramValues.length];
for (int i=0; i<paramValues.length; i++) {
try {
values[i] = Long.parseLong(paramValues[i]);
}
catch (Exception e) {
values[i] = defaultNum;
}
}
return values;
}
/**
* Gets a parameter as a string.
* @param request The HttpServletRequest object, known as "request" in a
* JSP page.
* @param name The name of the parameter you want to get
* @return The value of the parameter or null if the parameter was not
* found or if the parameter is a zero-length string.
*/
public static String getAttribute(HttpServletRequest request, String name) {
return getAttribute (request, name, false);
}
/**
* Gets a parameter as a string.
* @param request The HttpServletRequest object, known as "request" in a
* JSP page.
* @param name The name of the parameter you want to get
* @param emptyStringsOK Return the parameter values even if it is an empty string.
* @return The value of the parameter or null if the parameter was not
* found.
*/
public static String getAttribute(HttpServletRequest request,
String name, boolean emptyStringsOK)
{
String temp = (String)request.getAttribute(name);
if (temp != null) {
if (temp.equals("") && !emptyStringsOK) {
return null;
}
else {
return temp;
}
}
else {
return null;
}
}
/**
* Gets an attribute as a boolean.
* @param request The HttpServletRequest object, known as "request" in a
* JSP page.
* @param name The name of the attribute you want to get
* @return True if the value of the attribute is "true", false otherwise.
*/
public static boolean getBooleanAttribute(HttpServletRequest request,
String name)
{
String temp = (String)request.getAttribute(name);
if (temp != null && temp.equals("true")) {
return true;
}
else {
return false;
}
}
/**
* Gets an attribute as a int.
* @param request The HttpServletRequest object, known as "request" in a
* JSP page.
* @param name The name of the attribute you want to get
* @return The int value of the attribute or the default value if the
* attribute is not found or is a zero length string.
*/
public static int getIntAttribute(HttpServletRequest request,
String name, int defaultNum)
{
String temp = (String)request.getAttribute(name);
if (temp != null && !temp.equals("")) {
int num = defaultNum;
try {
num = Integer.parseInt(temp);
}
catch (Exception ignored) {}
return num;
}
else {
return defaultNum;
}
}
/**
* Gets an attribute as a long.
* @param request The HttpServletRequest object, known as "request" in a
* JSP page.
* @param name The name of the attribute you want to get
* @return The long value of the attribute or the default value if the
* attribute is not found or is a zero length string.
*/
public static long getLongAttribute(HttpServletRequest request,
String name, long defaultNum)
{
String temp = (String)request.getAttribute(name);
if (temp != null && !temp.equals("")) {
long num = defaultNum;
try {
num = Long.parseLong(temp);
}
catch (Exception ignored) {}
return num;
}
else {
return defaultNum;
}
}
}
发表评论
-
JSP界面显示科学计数法的解决
2011-09-21 11:03 6305数据库查出的值是形如0.0000422561993365776 ... -
将“回车(ENTER)”转成“切换(TAB)”的JS和jQuery写法
2011-07-28 16:59 2368普通js view plaincopy to clipboa ... -
url中文传递
2011-07-23 11:03 1391URL传递中文参数,默认格式为ISO-8859-1,一般在接收 ... -
重定向和内部转发的区别
2011-07-23 10:05 1942一、调用方式 我们知道 ... -
table与div互相嵌套注意
2011-03-28 14:09 3083本文介绍table与div互相嵌套的注意事项。 <!D ... -
html的tr和td标签
2011-03-28 14:06 3309tr 标签——代表HTML表格中的一行 1) tr 标签是成对 ... -
Struts2中表单与Action传递数据三种方式
2011-03-24 10:17 2628转自:http://gty.vip.blog.163.com/ ... -
Struts 项目中web.xml文件配置
2010-12-30 15:11 1821转载(http://blog.csdn.net/s ... -
struts1.3标签库问题
2010-01-02 17:18 1573在struts-1.3.10中并没有专门的tld文件,所以也不 ... -
struts标签库的导入
2010-01-02 14:39 6360使用Struts标签之前需要经过下面3个步骤的配置。 导入T ... -
sql注入及常用防护方法
2009-11-17 13:04 1741SQL 注入简介: SQL注入是最常见的攻击方式之一,它不是利 ... -
link标签
2009-11-15 14:17 1469link 就是将外部的文件导入内部。 例如你只有一个Html网 ... -
meta标签
2009-11-15 14:06 1076在网页的HTML源代码中一 ... -
安装版的tomcat使用指南
2009-11-12 16:53 3280准备java运行环境 Tomcat6 ... -
MyEclipse中 Address already in use:JVM_Bind:8080的错误情况
2009-11-06 19:47 1363当出现这种错误! 一般有两个问题 1.你的8080端口被别人占 ... -
jsp常见问题
2009-11-01 22:09 26641、 Servlet与JSP有什么区别? Servlet和JS ...
相关推荐
在这个"JSP参数接收工具类.rar"压缩包中,包含了两个重要的文件:"JSP参数接收工具类(ParamUtils.txt)"和"类加载工具.txt"。这些文件很可能是为了帮助开发者更方便地管理和处理JSP页面传入的请求参数,以及理解类...
总之,Smart2005中间件平台通过ParamUtils类提供了一套全面的工具,用于处理Web应用中的参数传递和类型转换。这些功能对于构建高效、可靠的互联网服务至关重要,它们帮助开发者快速响应用户请求,同时保持代码的整洁...
`ParamUtils`类根据setter方法的参数类型(如`int.class`、`Date.class`等),使用适当的转换方法(如`Integer.parseInt`、`SimpleDateFormat.parse`等)将字符串参数转换为正确的类型。 #### 总结 通过`...
4. **参数处理**:`ParamUtils.class`可能是一个工具类,用于处理HTTP请求中的参数,这在处理用户输入和数据验证时非常关键,确保了数据安全。 5. **图片资源**:`close.gif`和`reset.gif`是图形资源,常用于网页中...
这部分代码较为简单,主要负责获取请求参数并加载指定的论坛信息。具体代码如下: ```jsp long forumID = ParamUtils.getLongParameter(request, "forum", -1L); int start = ParamUtils.getIntParameter(request,...
- 开发及运行环境:定义开发环境,如Java开发工具(JDK)、集成开发环境(IDE,如Eclipse或IntelliJ IDEA),以及运行环境,如服务器软件(Tomcat)、数据库管理系统(MySQL)等。 - 数据库设计:设计数据库表结构,包括...
- **开发及运行环境**:选择合适的开发工具(如IDE、服务器)、编程语言(如Java)、框架(如Spring、Struts、Hibernate)和数据库(如MySQL、Oracle)。 - **数据库设计**:包括数据表设计、关系设计,确保数据的...
本文将详细介绍如何使用 Session 和 Cookie 实现网站自动登录的技术。 一、什么是 Session 和 Cookie? Session 和 Cookie 是两种常用的Web开发技术。Session 是一种服务器端的存储机制,用于存储用户的会话信息。...
校园网数据库,sql数据库的应用,有存储...String pagenumber = ParamUtils.getParameter(request,"page"); //out.println(UserManager.getUserProxy().showUserListByPage("","username",pagenumber)); %> </html>
if (ParamUtils.getBooleanParameter(request, "savePassword")) { // 设置密码相关的Cookie cookie = new Cookie("SESSION_LOGIN_PASSWORD", MD5.encode(u.getPassword())); cookie.setPath("/"); cookie....