简体   繁体   English

无法从一个控制器重定向到另一控制器-Spring MVC

[英]Unable to redirect from one controller to another controller-Spring MVC

I am new to spring MVC and facing some error. 我是Spring MVC的新手,面临一些错误。
I have two controllers as below 我有两个控制器,如下所示
1) LoginController.java 1) LoginController.java

@Controller
@RequestMapping("/log")
public class LoginController {
    @Autowired
    private LoginService service;

    @RequestMapping(value="login.spring",method=RequestMethod.GET) 
    public ModelAndView prepareLoginForm()
    {
        System.out.println("In get");
        return new ModelAndView("Login", "login", new Login());
    }

    @RequestMapping(value="login.spring",method=RequestMethod.POST) 
    public ModelAndView processLogin(@ModelAttribute("login") Login login,BindingResult result)
    {
        int i=service.validateLogin(login);
        if(i==0){
            return  new ModelAndView("redirect:login.spring");
        }

        ModelAndView view=new ModelAndView("redirect:Customer/Searchform.spring");


        return view;
    }

}

2) CustomerController.java 2) CustomerController.java

@Controller
@RequestMapping("/Customer")
public class CustomerController {

    @Autowired
    private CustomerService customerService;


    @RequestMapping(value="Searchform.spring",method=RequestMethod.GET)
    public  ModelAndView prepareCustomer()
    {
        System.out.println("In customer controller");
        CustomerSearchForm customerSearchForm=new CustomerSearchForm();
        return new ModelAndView("CustomerSearch","customerSearchForm",customerSearchForm);

    }


    @RequestMapping(value="Search.spring",method=RequestMethod.POST)
    public  ModelAndView searchCustomer(@ModelAttribute("customer") CustomerSearchForm customerSearchForm,BindingResult result)
    {
        int i=customerService.serachCustomer(customerSearchForm);
        if(i==1)
        return new ModelAndView("Holdings");

        return new ModelAndView("redirect:Customer");
    }
}

So after successful login I am trying to redirect to CustomerController but in browser url i can see that request url is http://localhost:8080/Online_Fund_Trading/log/Customer/Searchform.spring . 因此,成功登录后,我尝试重定向到CustomerController但是在浏览器URL中,我可以看到该请求URL为http://localhost:8080/Online_Fund_Trading/log/Customer/Searchform.spring As log gets added before Customer/Searchform.spring I am getting 404-The requested resource is not available error. 随着在Customer/Searchform.spring之前添加log ,我得到404-The requested resource is not available错误。

What changes are required to have request url as http://localhost:8080/Online_Fund_Trading/Customer/Searchform.spring . http://localhost:8080/Online_Fund_Trading/Customer/Searchform.spring请求网址为http://localhost:8080/Online_Fund_Trading/Customer/Searchform.spring需要进行哪些更改。

A simple slash / is required 需要一个简单的斜杠/

ModelAndView view=new ModelAndView("redirect:/Customer/Searchform.spring");

Otherwise the path will be considered relative to the path of the request you are currently handling. 否则,该路径将被视为相对于您当前正在处理的请求的路径。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将 POST 请求从一个控制器重定向到另一个控制器 Spring Boot - Redirect to a POST request from one controller to another controller Spring Boot 如何在Spring MVC中将LIST从一个控制器传递到另一个控制器 - How to pass LIST from one controller to another controller in spring mvc 从一种控制器方法到另一种方法的内部转发(Spring-MVC) - Internal forwarding from one controller method to another (Spring-MVC) 将日期值从一个控制器绑定到另一个:Spring MVC - Binding date values from one controller to another: Spring MVC 在Spring MVC中将HttpSession从一个控制器发送到另一个控制器 - Sending HttpSession from one controller to another in spring mvc 如何从一个Spring MVC控制器获取变量到另一个 - How to get variables from one Spring MVC Controller to Another 使用spring mvc 3将一个控制器重定向到另一个控制器 - redirecting one to another Controller using spring mvc 3 无法从Spring MVC中的控制器获取视图 - Unable to get the view from controller in spring mvc Spring MVC,从控制器内部调用另一个控制器 - Spring MVC, calling another controller from Inside a controller 下载或重定向错误消息到 Spring Web MVC 中的另一个控制器操作 - Download or redirect with error message to another controller action in Spring web MVC
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM