[英]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.