aspose file tools*
The moose likes Spring and the fly likes Controller is calling every action twice; therefore form is getting submitted twice. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Controller is calling every action twice; therefore form is getting submitted twice. " Watch "Controller is calling every action twice; therefore form is getting submitted twice. " New topic
Author

Controller is calling every action twice; therefore form is getting submitted twice.

Mahesh Bamane
Ranch Hand

Joined: Mar 12, 2008
Posts: 68
Hi,

I've been facing following issue in my project:
Controller is calling every action twice; therefore form is getting submitted twice.

I'm using spring mvc 3.

I's quite strange till yesterday code was running fine and suddenly I've started facing this issue.

Any suggestions/corrections are welcome.

Thanks.


There is nothing like trying, either you do it or you don't.
SCJP 1.5
Mahesh Bamane
Ranch Hand

Joined: Mar 12, 2008
Posts: 68
anyone to help on this please, something urgent and I'm not able to resolve. so..
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

You need to post more information

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

You need to post more information

Mark
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

What changed?

Mark
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

What changed?

Mark
Mahesh Bamane
Ranch Hand

Joined: Mar 12, 2008
Posts: 68
Hi Mark,

Thanks for your interest.

As far as I remember there nothing which changed drastically except an addition of one mapping.

Really know way to understand why controller is calling every mapping twice.
Is is something already faced in spring? I saw few posts on spring-forum n there it was happening because of empty img tag like .
I checked all my jsp pages n didn't find such an occurrence.

Thanks,
Mahesh
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

I doubt it has to do with an image.

Anyway, we really can't be of any help without more information/code. We can't see what mappings you have, what your configuration is? Maybe you have two equal mappings.

Mark
Mahesh Bamane
Ranch Hand

Joined: Mar 12, 2008
Posts: 68
Well, controller is calling every mapping twice it's not for a particular mapping that it's happening. So I've doubt whether it is something related to configuration.
I've two kind of url mappings so one is for /admin and one for /user.

Therefore I'm having two servlet-config files one is for /admin and /user and two servlets have been configured as follows.

<servlet>
<servlet-name>mvc-admin</servlet-name>
<servlet-class>com.myapp.servlets.AdminServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>

<servlet>
<servlet-name>mvc-user</servlet-name>
<servlet-class>com.myapp.servlets.userServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>

and have two controller one is adminController and other is userController.

and have mappings as follows:
in adminController:
@RequestMapping("/selectUser")
public ModelAndView admin(){
return new ModelAndView("/admin/getapplist","list", Application.getApplicationList());
}
in userController:
@RequestMapping("/showlist")
public ModelAndView user(UserForm form, ServletRequest request) {
ModelAndView modelAndView = new ModelAndView("/user/showlist");
modelAndView.addObject("list", Application.getApplicationList());

return modelAndView;
}
Thanks.
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

Huh, where in Spring MVC do you have to create your own servlets? Spring MVC uses just one servlet the DispatcherServlet.

I highly recommend reading the Core Spring documentation, in the section on Spring MVC. Right now, you are over-complicating things and adding things that shouldn't be there, and therefore all bets are off of anything working in that environment.

Or here is a well written simple tutorial just to make one simple Controller with all configuration.

http://www.mkyong.com/spring3/spring-3-mvc-hello-world-example/

Mark
Mahesh Bamane
Ranch Hand

Joined: Mar 12, 2008
Posts: 68
Thanks for assistance Mark, issue is resolved now.
Root cause was I'd written a filter which was calling doFilter twice.

Thanks again,
Mahesh
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

Mahesh Bamane wrote:Thanks for assistance Mark, issue is resolved now.
Root cause was I'd written a filter which was calling doFilter twice.

Thanks again,
Mahesh


Cool.

Still don't understand why you have those two servlets, but at least your issue is resolved.

Mark
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Controller is calling every action twice; therefore form is getting submitted twice.