HttpSession ss = request.getSession();
ss.getAttribute(AuthenticationProcessingFilter.SPRING_SECURITY_LAST_USERNAME_KEY)
AuthenticationProcessingFilter is depricated use UsernamePasswordAuthenticationFilter instead
Click here for more details
This will be useful, when u want to redirect to different page from your Authentication Providers using form-login tag in http security.
form-login login-page="/login.do" default-target-url="/something.do" authentication-failure-url="/loginfailure.do"
Wednesday, February 17, 2010
Wednesday, February 10, 2010
HashMap Sorting
public LinkedHashMap sortHashMap(HashMap uMap) {
List mKey = new ArrayList(uMap.keySet());
List mValues = new ArrayList(uMap.values());
Collections.sort(mValues);
Collections.sort(mKey);
LinkedHashMap sortedMap =
new LinkedHashMap();
Iterator valueIt = mValues.iterator();
while (valueIt.hasNext()) {
Object val = valueIt.next();
Iterator keyIt = mKey.iterator();
while (keyIt.hasNext()) {
Object key = keyIt.next();
String comp1 = uMap.get(key).toString();
String comp2 = val.toString();
if (comp1.equals(comp2)){
uMap.remove(key);
mKey.remove(key);
sortedMap.put((String)key, (String)val);
break;
}
}
}
return sortedMap;
}
Original Post Click here
List
List
Collections.sort(mValues);
Collections.sort(mKey);
LinkedHashMap
new LinkedHashMap
Iterator
while (valueIt.hasNext()) {
Object val = valueIt.next();
Iterator
while (keyIt.hasNext()) {
Object key = keyIt.next();
String comp1 = uMap.get(key).toString();
String comp2 = val.toString();
if (comp1.equals(comp2)){
uMap.remove(key);
mKey.remove(key);
sortedMap.put((String)key, (String)val);
break;
}
}
}
return sortedMap;
}
Original Post Click here
Tuesday, February 09, 2010
JAVA PreparedStatement with IN clause
JAVA PreparedStatement with IN clause
//two private methods.
private String phbuilder(int length) {
StringBuilder b = new StringBuilder();
for (int i = 0; i < length;) {
b.append("?");
if (++i < length) b.append(",");
}
return b.toString();
}
private void setValues(PreparedStatement ps, Object... values) throws SQLException {
for (int i = 0; i < values.length; i++) {
ps.setObject(i + 1, values[i]);
}
}
Usage
String sql = String.format("SELECT * FROM others_pocket WHERE id IN (%s)", phbuilder(ids.size()));
....
statement = connection.prepareStatement(sql);
setValues(statement, ids.toArray());
resultSet = statement.executeQuery();
For other alternatives pls take a look here
//two private methods.
private String phbuilder(int length) {
StringBuilder b = new StringBuilder();
for (int i = 0; i < length;) {
b.append("?");
if (++i < length) b.append(",");
}
return b.toString();
}
private void setValues(PreparedStatement ps, Object... values) throws SQLException {
for (int i = 0; i < values.length; i++) {
ps.setObject(i + 1, values[i]);
}
}
Usage
String sql = String.format("SELECT * FROM others_pocket WHERE id IN (%s)", phbuilder(ids.size()));
....
statement = connection.prepareStatement(sql);
setValues(statement, ids.toArray());
resultSet = statement.executeQuery();
For other alternatives pls take a look here
Friday, February 05, 2010
JSP Expression Language (c:if>...)
Implicit Objects
The JSP expression language defines a set of implicit objects:
* pageContext: The context for the JSP page. Provides access to various objects including:
o servletContext: The context for the JSP page's servlet and any web components contained in the same application. See Accessing the Web Context.
o session: The session object for the client. See Maintaining Client State.
o request: The request triggering the execution of the JSP page. See Getting Information from Requests.
o response: The response returned by the JSP page. See Constructing Responses.
In addition, several implicit objects are available that allow easy access to the following objects:
* param: Maps a request parameter name to a single value
* paramValues: Maps a request parameter name to an array of values
* header: Maps a request header name to a single value
* headerValues: Maps a request header name to an array of values
* cookie: Maps a cookie name to a single cookie
* initParam: Maps a context initialization parameter name to a single value
Finally, there are objects that allow access to the various scoped variables described in Using Scope Objects.
* pageScope: Maps page-scoped variable names to their values
* requestScope: Maps request-scoped variable names to their values
* sessionScope: Maps session-scoped variable names to their values
* applicationScope: Maps application-scoped variable names to their values
When an expression references one of these objects by name, the appropriate object is returned instead of the corresponding attribute. For example, ${pageContext} returns the PageContext object, even if there is an existing pageContext attribute containing some other value.
Literals
The JSP expression language defines the following literals:
* Boolean: true and false
* Integer: as in Java
* Floating point: as in Java
* String: with single and double quotes; " is escaped as \", ' is escaped as \', and \ is escaped as \\.
* Null: null
Operators
In addition to the . and [] operators discussed in Variables, the JSP expression language provides the following operators:
* Arithmetic: +, - (binary), *, / and div, % and mod, - (unary)
* Logical: and, &&, or, ||, not, !
* Relational: ==, eq, !=, ne, <, lt, >, gt, <=, ge, >=, le. Comparisons can be made against other values, or against boolean, string, integer, or floating point literals.
* Empty: The empty operator is a prefix operation that can be used to determine whether a value is null or empty.
* Conditional: A ? B : C. Evaluate B or C, depending on the result of the evaluation of A.
The precedence of operators highest to lowest, left to right is as follows:
* [] .
* () - Used to change the precedence of operators.
* - (unary) not ! empty
* * / div % mod
* + - (binary)
* < > <= >= lt gt le ge
* == != eq ne
* && and
* || or
* ? :
Reserved Words
The following words are reserved for the JSP expression language and should not be used as identifiers.
and eq gt true instanceof
or ne le false empty
not lt ge null div mod
Note that many of these words are not in the language now, but they may be in the future, so you should avoid using them.
Examples
Table 12-2 contains example EL expressions and the result of evaluating them.
Table 12-2 Example Expressions
EL Expression
Result
${1 > (4/2)}
false
${4.0 >= 3}
true
${100.0 == 100}
true
${(10*10) ne 100}
false
${'a' < 'b'}
true
${'hip' gt 'hit'}
false
${4 > 3}
true
${1.2E4 + 1.4}
12001.4
${3 div 4}
0.75
${10 mod 4}
2
${empty param.Add}
True if the request parameter named Add is null or an empty string
${pageContext.request.contextPath}
The context path
${sessionScope.cart.numberOfItems}
The value of the numberOfItems property of the session-scoped attribute named cart
${param['mycom.productId']}
The value of the request parameter named mycom.productId
${header["host"]}
The host
${departments[deptName]}
The value of the entry named deptName in the departments map
${requestScope['javax.servlet.
forward.servlet_path']}
The value of the request-scoped attribute named javax.servlet.
forward.servlet_path
Functions
The JSP expression language defines a set of implicit objects:
* pageContext: The context for the JSP page. Provides access to various objects including:
o servletContext: The context for the JSP page's servlet and any web components contained in the same application. See Accessing the Web Context.
o session: The session object for the client. See Maintaining Client State.
o request: The request triggering the execution of the JSP page. See Getting Information from Requests.
o response: The response returned by the JSP page. See Constructing Responses.
In addition, several implicit objects are available that allow easy access to the following objects:
* param: Maps a request parameter name to a single value
* paramValues: Maps a request parameter name to an array of values
* header: Maps a request header name to a single value
* headerValues: Maps a request header name to an array of values
* cookie: Maps a cookie name to a single cookie
* initParam: Maps a context initialization parameter name to a single value
Finally, there are objects that allow access to the various scoped variables described in Using Scope Objects.
* pageScope: Maps page-scoped variable names to their values
* requestScope: Maps request-scoped variable names to their values
* sessionScope: Maps session-scoped variable names to their values
* applicationScope: Maps application-scoped variable names to their values
When an expression references one of these objects by name, the appropriate object is returned instead of the corresponding attribute. For example, ${pageContext} returns the PageContext object, even if there is an existing pageContext attribute containing some other value.
Literals
The JSP expression language defines the following literals:
* Boolean: true and false
* Integer: as in Java
* Floating point: as in Java
* String: with single and double quotes; " is escaped as \", ' is escaped as \', and \ is escaped as \\.
* Null: null
Operators
In addition to the . and [] operators discussed in Variables, the JSP expression language provides the following operators:
* Arithmetic: +, - (binary), *, / and div, % and mod, - (unary)
* Logical: and, &&, or, ||, not, !
* Relational: ==, eq, !=, ne, <, lt, >, gt, <=, ge, >=, le. Comparisons can be made against other values, or against boolean, string, integer, or floating point literals.
* Empty: The empty operator is a prefix operation that can be used to determine whether a value is null or empty.
* Conditional: A ? B : C. Evaluate B or C, depending on the result of the evaluation of A.
The precedence of operators highest to lowest, left to right is as follows:
* [] .
* () - Used to change the precedence of operators.
* - (unary) not ! empty
* * / div % mod
* + - (binary)
* < > <= >= lt gt le ge
* == != eq ne
* && and
* || or
* ? :
Reserved Words
The following words are reserved for the JSP expression language and should not be used as identifiers.
and eq gt true instanceof
or ne le false empty
not lt ge null div mod
Note that many of these words are not in the language now, but they may be in the future, so you should avoid using them.
Examples
Table 12-2 contains example EL expressions and the result of evaluating them.
Table 12-2 Example Expressions
EL Expression
Result
${1 > (4/2)}
false
${4.0 >= 3}
true
${100.0 == 100}
true
${(10*10) ne 100}
false
${'a' < 'b'}
true
${'hip' gt 'hit'}
false
${4 > 3}
true
${1.2E4 + 1.4}
12001.4
${3 div 4}
0.75
${10 mod 4}
2
${empty param.Add}
True if the request parameter named Add is null or an empty string
${pageContext.request.contextPath}
The context path
${sessionScope.cart.numberOfItems}
The value of the numberOfItems property of the session-scoped attribute named cart
${param['mycom.productId']}
The value of the request parameter named mycom.productId
${header["host"]}
The host
${departments[deptName]}
The value of the entry named deptName in the departments map
${requestScope['javax.servlet.
forward.servlet_path']}
The value of the request-scoped attribute named javax.servlet.
forward.servlet_path
Functions
HttpServletRequest Objects
Many time encountered with trying to get servlet context, url, path , port number.
This is for reference.
Window Url:
http://localhost:8080/mycomp/myservlet?something=nothing
- request.getRequestURL().toString()
http://localhost:8080/mycomp/myservlet?something=nothing
- request.getContextPath().toString();
/mycomp
---------url.split(cntxt)[0]---------http://localhost:8080
----request.getProtocol()---------HTTP/1.1
----request.getServletPath()---------/myservlet
----request.getRemoteHost()--------0:0:0:0:0:0:0:1
---------url.split(cntxt)[0]---------http://localhost:8080
This is for reference.
Window Url:
http://localhost:8080/mycomp/myservlet?something=nothing
- request.getRequestURL().toString()
http://localhost:8080/mycomp/myservlet?something=nothing
- request.getContextPath().toString();
/mycomp
---------url.split(cntxt)[0]---------http://localhost:8080
----request.getProtocol()---------HTTP/1.1
----request.getServletPath()---------/myservlet
----request.getRemoteHost()--------0:0:0:0:0:0:0:1
---------url.split(cntxt)[0]---------http://localhost:8080
Spring Security ACL - Very basic tutorial Introduction
Spring Security ACL - very basic tutorial
Introduction
http://grzegorzborkowski.blogspot.com/2008/10/spring-security-acl-very-basic-tutorial.html
Introduction
http://grzegorzborkowski.blogspot.com/2008/10/spring-security-acl-very-basic-tutorial.html
Subscribe to:
Comments (Atom)