i have bean that contain method [void return] and want access to this bean in JSP.
public class A {
public void run() {}
}
add below code to spring config file.
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="exposeContextBeansAsAttributes" value="true"/>
</bean>
<bean id="a" class="com.example.A"
>
</bean>
now in my JSP page :
${a.run}
but this solution not work.please help me for access spring bean on JSP page.
Inject the bean into your controller and expose it as part of the model.
But why do you need to call
runfrom the JSP?JSP EL expects to follow JavaBean naming conventions; this example won’t work the way you expect. The easiest option is to rename the method, or provide an additional method, that follows the JavaBean naming convention and calls
run.Edit to reply to comment.
If you need to call a method from a link, you have two (reasonable) options: link to a controller action that calls the injected service, or make an Ajax call to a controller method that calls the injected service.
There’s still zero reason to be making the service call directly from the view layer (the JSP).