简体   繁体   中英

page not redirecting in controller

This my link

  <li class="active"><a href="/createform">Create Form</a></li>

this is my controller

@ResponseBody
@RequestMapping("/createform")
public String createform(Model uiModel, HttpServletRequest request)
{
    //some other codes
return "form";
}

and this is my view.xml

<definition name="form"  extends="default">
        <put-attribute name="content" value="/WEB-INF/views/jsps/tags/Form.jsp" />
    </definition>

My problem is Form.jsp is not opening.When hit the link the URL changes to `localhost:8080/pro/createform' but the contents of Form.jsp is not opening instead I am getting only one word "form".

When I debug then I can see the control is going to controller but the contents of Form.jsp is not opening

Can any body tell me the reason?

This may solve your problem

@ResponseBody
    @RequestMapping("/createform")
    public ModalAndView createform(Model uiModel, HttpServletRequest request)
    {
        //some other codes
    return new ModalAndView("Form");
    }
@ResponseBody
@RequestMapping("/createform")
public String createform(Model uiModel, HttpServletRequest request) {
    //some other codes
    return "form";
}

The problem is your code (above). You have annotated the method with @ResponseBody which, as the annotation name implies, will return the result as the body of the response. However you want to have a view and use a ViewResolver to select the correct view.

To fix this simply remove the @ResponseBody annotation.

@RequestMapping("/createform")
public String createform(Model uiModel, HttpServletRequest request) {
    //some other codes
    return "form";
}

Links

  1. @ResponseBody | javadoc
  2. @RequestMapping | javadoc

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM