-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathServletUtility.java
158 lines (128 loc) · 4.24 KB
/
ServletUtility.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
package ems.erp.util;
import java.io.IOException;
import java.util.List;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* This class provides utility operation for Servlet container like forward,
* redirect, handle generic exception=same time exception, manage success and
* error message, manage default Bean and List, manage pagination parameters
*
* @author Navigable Set
* @version 1.0
* @Copyright (c) Navigable Set
*/
public class ServletUtility {
public static void forward(String page, HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
RequestDispatcher rd = request.getRequestDispatcher(page);
System.out.println(page);
rd.forward(request, response);
}
public static void redirect(String page, HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
response.sendRedirect(page);
}
/* public static void handleException(Exception e, HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
request.setAttribute("exception", e);
ServletUtility.forward(ORSView.ERROR_CTL, request, response);
e.printStackTrace();
}
*/
public static String getErrorMessage(String property, HttpServletRequest request) {
String val = (String) request.getAttribute(property);
if (val == null) {
return "";
} else {
return val;
}
}
public static String getMessage(String property, HttpServletRequest request) {
String val = (String) request.getAttribute(property);
if (val == null) {
return "";
} else {
return val;
}
}
public static void setErrorMessage(String msg, HttpServletRequest request) {
//request.setAttribute(BaseCtl.MSG_ERROR, msg);
}
/*public static String getErrorMessage(HttpServletRequest request) {
String val = (String) request.getAttribute(BaseCtl.MSG_ERROR);
if (val == null) {
return "";
} else {
return val;
}
}
public static void setSuccessMessage(String msg, HttpServletRequest request) {
request.setAttribute(BaseCtl.MSG_SUCCESS, msg);
}
public static String getSuccessMessage(HttpServletRequest request) {
String val = (String) request.getAttribute(BaseCtl.MSG_SUCCESS);
if (val == null) {
return "";
} else {
return val;
}
}*/
/*public static void setBean(BaseBean bean, HttpServletRequest request) {
request.setAttribute("bean", bean);
}
public static BaseBean getBean(HttpServletRequest request) {
return (BaseBean) request.getAttribute("bean");
}
public static String getParameter(String property, HttpServletRequest request) {
String val = (String) request.getParameter(property);
if (val == null) {
return "";
} else {
return val;
}
}*/
public static void setList(List list, HttpServletRequest request) {
request.setAttribute("list", list);
}
public static List getList(HttpServletRequest request) {
return (List) request.getAttribute("list");
}
/**
* Sets Page Number for List pages
*
* @param pageNo
* @param request
*/
public static void setPageNo(int pageNo, HttpServletRequest request) {
request.setAttribute("pageNo", pageNo);
}
public static int getPageNo(HttpServletRequest request) {
return (Integer) request.getAttribute("pageNo");
}
public static void setPageSize(int pageSize, HttpServletRequest request) {
request.setAttribute("pageSize", pageSize);
}
public static int getPageSize(HttpServletRequest request) {
return (Integer) request.getAttribute("pageSize");
}
public static void setOpration(String msg, HttpServletRequest request) {
request.setAttribute("Opration", msg);
}
public static void setSize(int size, HttpServletRequest request) {
request.setAttribute("size", size);
}
public static int getSize(HttpServletRequest request) {
return (Integer) request.getAttribute("size");
}
public static String getOpration(HttpServletRequest request) {
String val = (String) request.getAttribute("Opration");
if (val == null) {
return "";
} else {
return val;
}
}
}