If you just want to invoke any Spring Bean Method from JSP using scriptlet here is the code for that:
Please not that here Spring Bean is:
Posted by Pankil Patel on July 7, 2011
If you just want to invoke any Spring Bean Method from JSP using scriptlet here is the code for that:
Please not that here Spring Bean is:
Posted in JSP, Spring | Leave a Comment »
Posted by Pankil Patel on August 22, 2010
Style 1: Configure property file to be used in spring xml
# Add new bean entry into your application context.
<bean id=”propertyConfigurer”
class=”org.springframework.beans.factory.config.PropertyPlaceholderConfigurer”>
<property name=”location”>
<value>classpath:abcConfig.properties</value>
</property>
</bean>
# Create new property file into src folder
abcConfig.properties
# Use that property file value
<property name=”user”>
<value>${jdbc.user}</value>
</property>
<property name=”password”>
<value>${jdbc.password}</value>
</property>
Style 2: Configure property file to be used in spring xml as well as in Java files
Step 1: Do All steps as in Style 1
Step 2: Add one more property called property-override with your “property-placeholder”
<context:property-override
location=”classpath:envSettings.properties” />
Step 3: Create one Java Class called “PathConfiguration” and add all properties & it’s setter, getter into this class. After that configure this class in your spring xml file like bellow.
<bean name=”pathConfiguration”
class=”co.cc.enlightensoft.service.common.PathConfiguration”>
</bean>
<bean
class=”org.springframework.web.context.support.ServletContextAttributeExporter”>
<property name=”attributes”>
<map>
<entry key=”pathConf” value-ref=”pathConfiguration” />
</map>
</property>
</bean>
Posted in Spring | Leave a Comment »
Posted by Pankil Patel on August 22, 2010
Step 1:
Create a class named “MailService”
package co.cc.enlightensoft.service.mail;
import javax.mail.internet.MimeMessage;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.mail.javamail.MimeMessageHelper;
public class MailService {
private static final Log LOG = LogFactory.getLog(MailService.class);
private JavaMailSenderImpl mailSender;
public void setMailSender(JavaMailSenderImpl mailSender) {
this.mailSender = mailSender;
}
public void sendMail(String from, String[] to, String subject, StringBuffer content) {
try {
MimeMessage message = mailSender.createMimeMessage();
MimeMessageHelper helper = new MimeMessageHelper(message, true);
helper.setFrom(from);
helper.setTo(to);
helper.setSubject(subject);
helper.setText(content.toString());
mailSender.send(message);
LOG.info(“Mail has been sent.”);
} catch (Exception ex) {
System.err.println(ex.getMessage());
LOG.error(“Exception while sending mail…” + ex.getMessage());
}
}
}
Step 2:
Create Two Spring Bean (1) mailSender and Use this bean into (2) mailService which is based on created file in step 1
<bean id=”mailSender” class=”org.springframework.mail.javamail.JavaMailSenderImpl”>
<property name=”host” value=”192.168.1.1″ />
</bean>
<bean name=”mailService”>
<property name=”mailSender” ref=”mailSender” />
</bean>
Step 3:
Use “mailService” Spring Bean into your service as a property injection to send email
Goooooooooooooooooooooood Luck…….. Enjoyeeeeeeeeeeeeeeeeeeeeeee…………
Posted in Spring | Leave a Comment »
Posted by Pankil Patel on June 9, 2010
Step 1:
Add three new class as described in Logging Using Spring AOP 2.0 / 3.0 just changes are, you need to implement interfaces ThrowsAdvice, MethodBeforeAdvice, AfterReturningAdvice respactively each for each class.
Step 2:
Add entry of these three bean and “adviceList” bean for logging into your applicationContext.xml as like below:
Now you need to add property “<property name=”adviceList” ref=”adviceList”/>” into your each Service bean definition of applicationContext.xml
Posted in Spring | Leave a Comment »
Posted by Pankil Patel on June 9, 2010
How to use Interceptor for logging each method in centralized manner?
Step 1:
Add Three new class for your logging say named ThrowsAdviceInterceptor, MethodBeforeAdviceInterceptor, AfterReturningAdviceInterceptor as like below:
Step 2:
Add entry of these three bean and AOP point cut for logging for Service layer into your applicationContext.xml
as like below:
Here in “aop:config” there is a parameter called: proxy-target-class=”true”
It is basically responsible for logging methods that are not covered into Services interfaces.
And for this you required cglib.jar
Jar used in this example are:
aspectjweaver-1.6.5.jar aspectjrt-1.6.5.jar cglib-2.2.jar asm-3.1.jarPosted in Spring | 2 Comments »
Posted by Pankil Patel on April 30, 2010
How to use role base access into jsp with Spring Security 3.0?
or
How to render component / tag using defined role of Spring Security 3.0 into jsp?
Step 1:
Include <%@ taglib prefix=”sec” uri=”http://www.springframework.org/security/tags” %> into your jsp page. And use <sec:authorize> tag to render role base component Like:
Note:
Please make sure that you have entry “/case/admin” into your “http” section of “applicationContext-security.xml” file like:
That’s it for using role into jsp……
Hureeeeeeeeeeee Ready to use access mechanism of spring Security 3.0. into your jsp.
BEST OF LUCK
Posted in Spring | Leave a Comment »
Posted by Pankil Patel on April 30, 2010
How to Handle Authentication Fail when we are using “Custom EntryPoint” or “Custom authenticationProcessingFilter” or ” Custom UsernamePasswordAuthenticationFilter” in Spring Security 3.0?
Step 1:
Add new bean entry of “authenticationFailureHandler” into your “applicationContext-security.xml” file like:
Here languageProcessingFilter is the same as explained in post Spring Security 3 .0 – Part 3.
Step 2:
Create your new class “AuthenticationFailHandler” Which will implements “org.springframework.security.web.authentication.AuthenticationFailureHandler” Like:
That’s it for Authentication Fail Handling……
Hureeeeeeeeeeee Ready to use Customized spring Security 3.0. with Authentication Fail Handling.
BEST OF LUCK
Posted in Spring | Leave a Comment »
Posted by Pankil Patel on April 14, 2010
How you will Handle “default-target-url” of “form-login” tag when you are using your custom Entry Point?
When you are using Custom Entry Point, say Using “UsernamePasswordAuthenticationFilter” and you want the same behavior as like “default-target-url” functionality of “form-login” from “HTTP” section than in your Customized Class say “MyAuthenticationProcessingFilter” (as in Spring Security 3.0 – Part 3) you have to Override one more method that is “successfulAuthentication”. Say like:

Please Note: Here return statement of getParameter method is like ‘ return “/login/homePage.action?request_locale=” + selectedLanguage; ‘ this means that you are also passing extra parameter(language) to the action which is passed from your Login page. If you simply want to call homePage Action without passing that parameter your return statment will be like: ‘ return “/login/homePage.action”; ‘
Yeeeeeeee I am able to call my homeAction After successful Authentication using spring Security 3.0.
BEST OF LUCK
Posted in Spring | 3 Comments »
Posted by Pankil Patel on April 14, 2010
How to pass extra parameter(s) from login page in Spring Security 3.0?
OR
How to create “Custom EntryPoint” or “Custom authenticationProcessingFilter” or ” Custom UsernamePasswordAuthenticationFilter” in Spring Security 3.0?
Step 1:
Add you extra parameter into your jsp / html page along with “j_username” and “j_password”. like:

Step 2:
Create new java file Say named “MyAuthenticationProcessingFilter.java” which will extends “org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter”.
Override method setDetails in MyAuthenticationProcessingFilter Class in that method you have request and from that request you can easily get your extra parameter passed from your jsp / html via Spring Security.
@Override
protected void setDetails(HttpServletRequest request, UsernamePasswordAuthenticationToken authRequest) {
super.setDetails(request, authRequest);
String selectedLanguage = request.getParameter(“request_locale”);
}
Step 3:
To achieve this Custom UsernamePasswordAuthentication you must change you “applicationContext-security.xml” file like:
Please Note: Here in “applicationContext-security.xml” file effective changes than Spring Security 3.0 – Part 1 are:
1) http start tage ‘ auto-config=”false” entry-point-ref=”authenticationProcessingFilterEntryPoint” ‘
2) “form-login” removed from http section
3) “custom-filter” added into http section
4) Added Two more Spring Bean definition “languageProcessingFilter” and “authenticationProcessingFilterEntryPoint”
All Set for these Customization……..
Hureeeeeeeeeeee Ready to use Customized spring Security 3.0.
BEST OF LUCK
Posted in Spring | 2 Comments »
Posted by Pankil Patel on April 12, 2010
How to add method level spring security 3.0 in your project?
Step 1:
Before proceeding for method level in spring security 3.0 basic security should be integrated in your project as explain in Spring Security 3.0 – Part 1
Step 2:
Add “global-method-security” in your applicationContext-security.xml file before “http” tag like: 
Step 3:
Add annotation on your method of Spring / Business layer Service.
For example: You have interface “UserDetailService.java” which is implemented by your spring service “UserDetailServiceImpl.java” and you have method called “saveUser” defined in “UserDetailService.java” and implemented in “UserDetailServiceImpl.java” and you want some ROLL Based security on this method so you have to right like this:

Note: Here we are adding method level security into the service file not in the Implementing file.
Hurre…………………….
All set now method level spring security 3.0 is ready to use for your project.
BEST OF LUCK
How to use this ROLL Base spring security to render some JSP / HTML tag?
Posted in Spring | Leave a Comment »