📄 formutil.java
字号:
package com.baosight.util;
import java.util.*;
import javax.servlet.http.*;
public class FormUtil {
private HashMap values = new HashMap();
public static boolean encoding = true;
public static final String DATE_FORMAT = "yyyymmdd";
public boolean hasValues = false;
public FormUtil(HttpServletRequest request) throws Exception{
values = input(request);
if(values.size() >0 ){
hasValues= true;
}
}
public boolean hasValues(){
return hasValues;
}
public HashMap getValues(){
return values;
}
public static HashMap input(HttpServletRequest request)
throws Exception {
// if( encoding ){
// request.setCharacterEncoding("GBK");
// }
HashMap properties = new HashMap();
Enumeration names = request.getParameterNames();
while (names.hasMoreElements()) {
String name = (String) names.nextElement();
String[] values= request.getParameterValues(name);
if( encoding ){
for( int i=0;i<values.length;i++){
String val = StringUtil.native2unicode(values[i]);
values[i] = val;
}
}//end of if( encoding )
if( values.length == 1 ){
properties.put(name, values[0]);
}else{
properties.put(name, values);
}
}
return properties;
}
public boolean hasValue(String name){
if( name == null) return false;
if( values.get(name) == null ){
return false;
}else{
return true;
}
}
public String getString(String name){
if( name == null) return null;
if( values.get(name) == null ){
return "";
}
String rt = (String)values.get(name);
rt.trim();
return rt;
}
public void setString(String name){
if( name == null)
if( values.get(name) == null ){
}
String rt = (String)values.put("oper","");
rt.trim();
}
public int getInt(String name){
if( values.get(name) == null ){
throw new RuntimeException("can not find form value named:"+ name);
}
String rt = (String)values.get(name);
rt.trim();
try{
int rti = new Integer( rt).intValue();
return rti ;
}catch(Exception e){
throw new RuntimeException(
"can not convert form's element <"+name+"> (which value is "+ rt +" ) to int"
);
}
}
public double getDouble(String name) throws Exception{
if( values.get(name) == null ){
throw new NoSuchFieldException("can not find form value named:"+ name);
}
String rt = (String)values.get(name);
rt.trim();
try{
double rti = new Double( rt).doubleValue();
return rti ;
}catch(Exception e){
throw new RuntimeException(
"can not convert form's element <"+name+"> (which value is "+ rt +" ) to double"
);
}
}
public float getFloat(String name) throws Exception{
if( values.get(name) == null ){
throw new NoSuchFieldException("can not find form value named:"+ name);
}
String rt = (String)values.get(name);
rt.trim();
try{
float rti = new Float( rt).floatValue();
return rti ;
}catch(Exception e){
throw new RuntimeException(
"can not convert form's element <"+name+"> (which value is "+ rt +" ) to float"
);
}
}
public String[] getArray(String name) throws Exception{
if( values.get(name) == null ){
throw new NoSuchFieldException("can not find form value named:"+ name);
}
String[] rt = (String[])values.get(name);
return rt;
}
public java.util.Date getDate(String name) throws Exception{
if( values.get(name) == null ){
throw new NoSuchFieldException("can not find form value named:"+ name);
}
String rt = (String)values.get(name);
rt.trim();
return TimeUtil.getDate(rt,DATE_FORMAT);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -