Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
C
common
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
曲欣亮
common
Commits
c5b29911
Commit
c5b29911
authored
Aug 22, 2019
by
Quxl
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of
http://key@gitlab.egolm.com/key/common.git
parents
9643dbbf
59d59db7
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
88 additions
and
72 deletions
+88
-72
ServletUtil.java
src/main/java/com/egolm/common/web/ServletUtil.java
+88
-72
No files found.
src/main/java/com/egolm/common/web/ServletUtil.java
View file @
c5b29911
package
com
.
egolm
.
common
.
web
;
package
com
.
egolm
.
common
.
web
;
import
java.net.InetAddress
;
import
java.io.UnsupportedEncodingException
;
import
java.net.URLDecoder
;
import
java.net.InetAddress
;
import
java.net.UnknownHostException
;
import
java.net.URLDecoder
;
import
java.util.Enumeration
;
import
java.net.URLEncoder
;
import
java.net.UnknownHostException
;
import
javax.servlet.http.HttpServletRequest
;
import
java.util.Enumeration
;
import
com.egolm.common.StringUtil
;
import
javax.servlet.http.HttpServletRequest
;
import
com.egolm.common.exception.PluginException
;
import
com.egolm.common.StringUtil
;
public
class
ServletUtil
{
import
com.egolm.common.exception.PluginException
;
public
static
String
remoteIp
(
HttpServletRequest
request
)
{
public
class
ServletUtil
{
String
ip
=
request
.
getHeader
(
"X-Real_IP"
);
if
(
ip
==
null
||
ip
.
length
()
==
0
||
ip
.
equalsIgnoreCase
(
"unknown"
))
{
public
static
String
remoteIp
(
HttpServletRequest
request
)
{
ip
=
request
.
getHeader
(
"X-Forwarded-For"
);
String
ip
=
request
.
getHeader
(
"X-Real_IP"
);
}
if
(
ip
==
null
||
ip
.
length
()
==
0
||
ip
.
equalsIgnoreCase
(
"unknown"
))
{
if
(
ip
==
null
||
ip
.
length
()
==
0
||
ip
.
equalsIgnoreCase
(
"unknown"
))
{
ip
=
request
.
getHeader
(
"X-Forwarded-For"
);
ip
=
request
.
getHeader
(
"Proxy-Client-IP"
);
}
}
if
(
ip
==
null
||
ip
.
length
()
==
0
||
ip
.
equalsIgnoreCase
(
"unknown"
))
{
if
(
ip
==
null
||
ip
.
length
()
==
0
||
ip
.
equalsIgnoreCase
(
"unknown"
))
{
ip
=
request
.
getHeader
(
"Proxy-Client-IP"
);
ip
=
request
.
getHeader
(
"WL-Proxy-Client-IP"
);
}
}
if
(
ip
==
null
||
ip
.
length
()
==
0
||
ip
.
equalsIgnoreCase
(
"unknown"
))
{
if
(
ip
==
null
||
ip
.
length
()
==
0
||
ip
.
equalsIgnoreCase
(
"unknown"
))
{
ip
=
request
.
getHeader
(
"WL-Proxy-Client-IP"
);
ip
=
request
.
getRemoteAddr
();
}
}
if
(
ip
==
null
||
ip
.
length
()
==
0
||
ip
.
equalsIgnoreCase
(
"unknown"
))
{
String
[]
ips
=
ip
.
trim
().
split
(
", "
);
ip
=
request
.
getRemoteAddr
();
return
ips
[
ips
.
length
-
1
].
trim
();
}
}
String
[]
ips
=
ip
.
trim
().
split
(
", "
);
return
ips
[
ips
.
length
-
1
].
trim
();
public
static
String
getLocalIP
()
{
}
try
{
return
InetAddress
.
getLocalHost
().
getHostAddress
();
public
static
String
getLocalIP
()
{
}
catch
(
UnknownHostException
e
)
{
try
{
throw
new
PluginException
(
e
);
return
InetAddress
.
getLocalHost
().
getHostAddress
();
}
}
catch
(
UnknownHostException
e
)
{
}
throw
new
PluginException
(
e
);
/**
}
*
}
* @Description 读取传入的json字符
/**
* @param request
*
* @return
* @Description 读取传入的json字符
* @return String
* @param request
* @throws
* @return
* @author 曲欣亮
* @return String
* @date 2016年5月17日
* @throws
* @since 2016年5月17日
* @author 曲欣亮
*/
* @date 2016年5月17日
public
static
String
readReqJson
(
HttpServletRequest
request
)
{
* @since 2016年5月17日
String
json
=
""
;
*/
try
{
public
static
String
readReqJson
(
HttpServletRequest
request
)
{
Enumeration
<?>
names
=
request
.
getParameterNames
();
String
json
=
""
;
if
(
names
.
hasMoreElements
())
{
try
{
json
=
(
String
)
names
.
nextElement
();
Enumeration
<?>
names
=
request
.
getParameterNames
();
}
if
(
names
.
hasMoreElements
())
{
if
(
json
==
null
||
json
.
length
()
==
0
)
{
json
=
(
String
)
names
.
nextElement
();
json
=
StringUtil
.
read
(
request
.
getReader
());
}
}
if
(
json
==
null
||
json
.
length
()
==
0
)
{
}
catch
(
Exception
e
)
{
json
=
StringUtil
.
read
(
request
.
getReader
());
e
.
printStackTrace
();
}
}
}
catch
(
Exception
e
)
{
try
{
e
.
printStackTrace
();
String
encodeJson
=
URLDecoder
.
decode
(
json
,
"UTF-8"
);
}
return
encodeJson
;
try
{
}
catch
(
Exception
e
)
{
String
encodeJson
=
URLDecoder
.
decode
(
json
,
"UTF-8"
);
e
.
printStackTrace
();
return
encodeJson
;
return
json
;
}
catch
(
Exception
e
)
{
}
e
.
printStackTrace
();
}
return
json
;
}
}
}
public
static
String
covertFileName
(
HttpServletRequest
request
,
String
fileName
)
throws
UnsupportedEncodingException
{
String
userAgent
=
request
.
getHeader
(
"User-Agent"
).
toLowerCase
();
System
.
out
.
println
(
userAgent
);
String
excelFileName
=
""
;
if
(
userAgent
.
indexOf
(
"msie"
)
!=
-
1
)
{
// IE浏览器
excelFileName
=
URLEncoder
.
encode
(
fileName
,
"UTF8"
);
}
else
if
(
userAgent
.
indexOf
(
"firefox"
)
!=
-
1
)
{
// google,火狐浏览器
excelFileName
=
new
String
(
fileName
.
getBytes
(),
"ISO-8859-1"
);
}
else
{
excelFileName
=
URLEncoder
.
encode
(
fileName
,
"UTF8"
);
// 其他浏览器
}
return
excelFileName
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment