Back Forum Reply New

Calling a Java class method from within JSP

Hi,

I have a JSP page which is loaded from a Controller class via -Code:
......
public ModelAndView handleRequest(fromServletRequest request, fromServletResponse response) throws ServletException, IOException
{
dbQuery();
ModelAndView mav = new ModelAndView(quot;homequot;);
mav.addObject(quot;sysObjquot;, resultList);
return mav;   
}
.....
And thus control flows from COntroller layer to view layer.However in home.jsp I need to do some event handling. As in, when user clicks on a text/link another method needs to be run in Java class returning resultList2 which will be displayed in JSP along with original resultList. i.e. how can I access a method from within view layer without defining a new bean in application-servlet.xml file?

What are possible options?Thanks

A call from a JSP will actually be a call from the client. So that means another from call via JavaScript. You could expose those methods through DWR, or expose multiple methods in your controller with a MultiActionController.

this mode sounds more like JSF which if I am not mistaken does just that, linking client side events to server side methods using stanard POST. A very different model from the page oriented spring MVC.

Though you would still need to define those java class as JSF managed beans.

The only problem I have with this model is that it can be very inefficient so may be DWR(or other ajax style) is a better option.

Hi,

Thanks for the replies. I believe MultiActionController is what I was looking out for. I tried writing a sample code, using sample code provided in a book - Spring in Action. However I am unable to call the method. Any inputs what I must be doing wrong -

web.xml -Code:
lt;servletgt;
lt;servlet-namegt;springapplt;/servlet-namegt;
lt;servlet-classgt;org..web.servlet.DispatcherServletlt;/servlet-classgt;
lt;load-on-startupgt;1lt;/load-on-startupgt;
lt;/servletgt;

sprinapp-servlet.xml -Code:
lt;bean name=quot;/listIt.htmquot;     class=quot;SpringappMultiControllerquot;gt;
lt;/beangt;

lt;bean id=quot;paramResolverquot; class=quot;org..web.servlet.mvc.multiaction.ParameterMethodNameResolverquot;gt;
lt;property name=quot;paramNamequot;gt;lt;valuegt;methodlt;/valuegt;lt;/propertygt;
lt;/beangt;

lt;bean id=quot;paramMultiControllerquot; class=quot;org..web.servlet.mvc.multiaction.MultiActionControllerquot;gt;
lt;property name=quot;methodNameResolverquot;gt;lt;ref bean=quot;paramResolverquot;/gt;lt;/propertygt;
lt;property name=quot;delegatequot;gt;lt;ref bean=quot;sampleDelegatequot;/gt;lt;/propertygt;
lt;/beangt;

lt;bean id=quot;sampleDelegatequot; class=quot;SpringappMultiControllerquot;/gt;
SpringappMultiController.java -Code:
import org..web.servlet.mvc.multiaction.*;
import org..web.servlet.*;
import javax.servlet.from.*;
import org..web.context.support.WebApplicationContextUtils;public class SpringappMultiController extends MultiActionController {

public ModelAndView actionName(fromServletRequest req, fromServletResponse res)
{
//String somethingString = quot;testing getSomethingquot;;
return new ModelAndView(quot;testquot;);
}

}

When I pass on the ucl -
SPRINGWEBFLO...hod=actionName

===
org..web.servlet.PageNotFound  No request handling method with name 'listIt' in class [SpringappMultiController]
===Hence it is getting mapping between listIt.htm and the class; however the ParameterMethodNameResolver mapping is somehow not working.

Any tips?Thanks
¥
Back Forum Reply New