Simple URL mapping in Springs MVC

149 views
Skip to first unread message

shweta sharma

unread,
Jan 22, 2010, 3:08:38 AM1/22/10
to bo...@googlegroups.com
Hi ,
 
I am new to SPRINGS MVC  framework & struggling with it .
 
As compared to struts where developing app is  smooth its very complicated in SPRINGS to me.
 
here I have 2 problems.
 
1) how to direct  refer to a simple jsp page  without defining any Class.
 
i mean as in struts to refer toa  jsp page  we just give
<action path="/modAPP/myService"
                                 forward="/modAPP/myService.jsp">
 
here its not madatory to  call any class implementation . how  can it be achieved in SPRINGS.
 
Till now i am refering jsp pages  by  implementing a handler class.
 
like

<bean name="/hello.htm" class="mySpringPrj.web.InventoryController">

<property name="productManager" ref="productManager"/>

</bean>

is it mandatory to  implement a class for a jsp  ?

 
2) If my jsp page contains  multiple forms ( each form  has different actions to be called on submission )
how can  it be done in spings.
 
Any idea about  above  2 probs .
 
Thanks in advance .
Shweta

Rajnish

unread,
Jan 22, 2010, 6:26:38 AM1/22/10
to bo...@googlegroups.com
 
Regards,
 
Rajnish

On Fri, Jan 22, 2010 at 4:52 PM, Rajnish <raj19...@gmail.com> wrote:

Handling Requests:

When a request comes to the DispatcherServlet, you may want to take it through different stages. In this framework, you can configure handlers to do this. There are many handlers available that can be used by providing handler mappings. Since you want to take the request through different process steps, the handler must be able to process the request for a definite task and forward the request to next handler in chain. For this it must also contain the list of handlers applied to this request.

  • BeanNameUrlHandlerMapping: Extends from AbstractHandlerMapping. Maps incoming HTTP request to the bean names configured in application context i.e. as a bean name, in application context, we give url and the bean is of a controller. Thus the url is mapped to a controller.

<bean name=”/saveCustomer.htm”   class=”com.myorg.springmvctutorial.web.controller.SaveCustomerController”/>

  • SimpleUrlHandlerMapping: Extends from AbstractHandlerMapping. More powerful and supports Ant-style url mapping. This mapping we configure at two places. In web.xml we define the url pattern supported.

<servlet-mapping>

<servlet-name>springmvctutorial</servlet-name>

<url-pattern>*.html</url-pattern>

</servlet-mapping>

In application context xml, we map the urls to controller definitions.

<bean class=”org.springframework.web.servlet.handler.SimpleUrlHandlerMapping”>

<property name=”mappings”>

<value>

/*/saveCutomer.htm= saveCustomerController

</value>

</property>

</bean>
 
HandlerIntercepter: Implementer of this intercept can implement three methods of this intercepter, one that is called before the actual handler execution, second after the handler execution and last one after the complete request processing. Handlers can be configured using SimpleUrlHandlerMapping configuration in application context.
 
I am sending to you one example check that attachment
 
Regards,
 
Rajnish

--
You received this message because you are subscribed to the Google Groups "Bangalore Open Java Users Group- BOJUG" group.
To post to this group, send email to bo...@googlegroups.com.
To unsubscribe from this group, send email to bojug+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/bojug?hl=en.


Rajnish

unread,
Jan 22, 2010, 6:22:26 AM1/22/10
to bo...@googlegroups.com

Handling Requests:

When a request comes to the DispatcherServlet, you may want to take it through different stages. In this framework, you can configure handlers to do this. There are many handlers available that can be used by providing handler mappings. Since you want to take the request through different process steps, the handler must be able to process the request for a definite task and forward the request to next handler in chain. For this it must also contain the list of handlers applied to this request.

  • BeanNameUrlHandlerMapping: Extends from AbstractHandlerMapping. Maps incoming HTTP request to the bean names configured in application context i.e. as a bean name, in application context, we give url and the bean is of a controller. Thus the url is mapped to a controller.

<bean name=”/saveCustomer.htm”   class=”com.myorg.springmvctutorial.web.controller.SaveCustomerController”/>

  • SimpleUrlHandlerMapping: Extends from AbstractHandlerMapping. More powerful and supports Ant-style url mapping. This mapping we configure at two places. In web.xml we define the url pattern supported.

<servlet-mapping>

<servlet-name>springmvctutorial</servlet-name>

<url-pattern>*.html</url-pattern>

</servlet-mapping>

In application context xml, we map the urls to controller definitions.

<bean class=”org.springframework.web.servlet.handler.SimpleUrlHandlerMapping”>

<property name=”mappings”>

<value>

/*/saveCutomer.htm= saveCustomerController

</value>

</property>

</bean>
 
HandlerIntercepter: Implementer of this intercept can implement three methods of this intercepter, one that is called before the actual handler execution, second after the handler execution and last one after the complete request processing. Handlers can be configured using SimpleUrlHandlerMapping configuration in application context.
 
I am sending to you one example check that attachment
 
Regards,
 
Rajnish

On Fri, Jan 22, 2010 at 1:38 PM, shweta sharma <shwe...@gmail.com> wrote:
--

shweta sharma

unread,
Jan 28, 2010, 9:02:38 AM1/28/10
to bo...@googlegroups.com
Hi,
 
I have a  form where i  have to insert data into table on submission.
 
I am able to do it  with simple user entered values.
 
But now i want to   select  data  from drop down list that will come from another table in the same  form  that needs to be submitted.
 
But here i am not able to fetch data  in drop down.
 
because in springs  it is calling class only on submit.
 
I  called getPartyList() method in PartyController .
but  it is getting called only on submit as per below  mapping in app-servlet.xml.
 

<bean name="/partyForm.htm" class="TallyPrj.web.PartyController">

<property name="sessionForm" value="true"/>

<property name="commandName" value="addParty"/>

<property name="commandClass" value="TallyPrj.form.Party"/>

<property name="formView" value="partyForm"/>

<property name="successView" value="hello.htm"/>

<property name="productManager" ref="productManager"/>

</bean>

How can i get  data from a table  in form ?

 

I tried  to redirect  through a URL that calles  another class
 
I mean added

<bean name="/account.htm" class="TallyPrj.web.AccountController">

<property name="productManager" ref="productManager"/>

</bean>

that will call AccountController class ( having below code)

public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response)

throws ServletException, IOException {

String now = (

new java.util.Date()).toString();

logger.info("returning hello view with " + now);

Map<String, Object> myModel =

new HashMap<String, Object>();

myModel.put(

"parties", this.productManager.getPartyList());

return new ModelAndView(new RedirectView("/partyForm"), "model", myModel);

}

 

but  now it is showing  :: HTTP 404 The requested resource (/partyForm) is not available.

 

I tried in many ways .. but  its not coming.

Any help in this regard will be appreciable.

 

Thanks in advance

shweta

shweta sharma

unread,
Jan 31, 2010, 9:54:46 AM1/31/10
to bo...@googlegroups.com
Hi ,
 
MY pronlem is solved.
 
 
Overriding   referenceData() method  will  load the model that can be accessed in  the form when it will loaded .
 
regards
Shweta

Reply all
Reply to author
Forward
0 new messages