views:

33

answers:

1

Hi all,

I'm new to Java WEB Development please help with this !!

my link in the action-servlet is

http://myproject.co.in:9090/a/userSignUp.action

i got a new user registration page and i have given an action for the log in button..

but if i click the button its redirecting to this page ..

please help and thank you for your time and kindness !!

here's my code

for userSignUp.action - controller is LoginController and the jsp has login and password text fields and a submit button.

on click of that button userHome.action is called..

and here's my code

<bean id="handlerMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
    <property name="mappings">
        <props>
            <prop key="/api/Logout.action">LogoutController</prop>
            <prop key="/secure/userSignUp.action">LoginController</prop>
            <prop key="/a/userHome.action">userHomeController</prop>
        </props>
    </property>
</bean>

and for the bean id i'm posting a controller

<bean id="userHomeController" class="com.ghg.web.controller.UserHomeController" autowire="byName"/> 

and in that controller

    public final ModelAndView handleRequest(HttpServletRequest request,HttpServletResponse response) throws Exception {
    log.debug("-- At User Home Controller --");
    return new ModelAndView("/user/userHome.jsp");
}

in userHome.jsp there's no code just a plain html text

A: 

I'm assuming you want your userSignUp.action to post to the same page?

In order to do that, you need to define two different RequestMappings with the same value but different RequestMethods. Here is an example from one of my webapps:

//rendering form
@RequestMapping(value = "add.do", method = RequestMethod.GET)
public String showUserForm(ModelMap model) {
    IlbiUser user = new IlbiUser();
    model.addAttribute("user", user);
    return formView;
}

//submitting form
@RequestMapping(value = "add.do", method = RequestMethod.POST)
public String onSubmitUserForm(@ModelAttribute("user") IlbiUser user, BindingResult result) {
    userValidator.validate(user, result);
    if (result.hasErrors()) {
        return formView;
    } else {
        userService.addUser(user);
        return successView;
    }
}

You see? I think you have only defined the GET-Method for your RequestMapping.

If that's not what you're looking for, you should try an be more precise with your question and/or give us some more code to work with :p

greetings

chzbrgla
Thanks for the help before i have edited the Question and posted some code please have a check
javatechi
Ok. so my answer seems to be what you're looking for. You're always doing the same regardless of the requests's method. Get the requests method first and then change your method accordingly. But I would recommend switching to Annotation Controllers anyways. http://static.springsource.org/spring/docs/2.5.x/reference/mvc.html
chzbrgla
If you're not prone to switching:http://download.oracle.com/javaee/1.3/api/javax/servlet/http/HttpServletRequest.html#getMethod()Use that method to find out if you have to show the form or do the form validation
chzbrgla
thanks for the help @chrzbrgla
javatechi