請在下面找到該代碼:viewresolver無法重定向到春季的正確視圖
viewResolver無法直接從控制器重定向到所需的視圖。我在控制器中打印視圖名稱。所打印的視圖名是正確的。但最終它登陸到一個新的網址!
請在下面找到細節!
控制器
package in.co.linq.StudentAdmissionController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.portlet.ModelAndView;
@Controller
public class StudentAdmissionController {
public StudentAdmissionController()
{
super();
System.out.println("StudentAdmissionController Constructor!!");
}
@RequestMapping(value="/Register" ,method=RequestMethod.GET)
public ModelAndView getRegisterForm()
{
ModelAndView modelAndView =new ModelAndView("Register");
modelAndView.addObject("msg","Register Me");
System.out.println("In getRegisterForm");
return modelAndView;
}
@RequestMapping(value="/HelloPage.html",method=RequestMethod.POST)
public ModelAndView submitRegisterForm(@RequestParam("txtname") String name,@RequestParam("txtcollege") String college
) {
ModelAndView modelAndView =new ModelAndView("HelloPage","msg", "Congrats!! Form submitted for "+name +" in college"+college);
//modelAndView.addObject("msg", "Congrats!! Form submitted for "+name +" in college"+college);
//modelAndView.addObject("college", college);
System.out.println(name+college);
System.out.println("In submitRegisterForm");
System.out.println(modelAndView.getViewName());
System.out.println(modelAndView.getModel());
return modelAndView;
}
@RequestMapping(value="/HelloPage/{countryName}/{userName}",method=RequestMethod.GET)
public ModelAndView method(@PathVariable("userName") String userName,@PathVariable("countryName") String countryName) {
ModelAndView modelAndView =new ModelAndView("HelloPage","msg", "Congrats!! Form submitted for "+userName+countryName);
//modelAndView.addObject("msg", "Congrats!! Form submitted for "+name +" in college"+college);
//modelAndView.addObject("college", college);
System.out.println(userName+countryName);
System.out.println("In submitRegisterForm");
System.out.println(modelAndView.getViewName());
System.out.println(modelAndView.getModel());
return modelAndView;
}
}
分配器一servlet.xml中
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver" >
<property name="prefix">
<value>/WEB-INF/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
的錯誤網址上找到控制檯
INFO: Mapped URL path [/studentadmission/*] onto handler 'studentAdmissionController'
Jun 30, 2015 11:32:54 AM org.springframework.web.servlet.DispatcherServlet initServletBean
INFO: FrameworkServlet 'SD-StudentAdmission': initialization completed in 19601 ms
上 http://localhost:8080/SpringMVCUsingRequestParam/HelloPage.html/India/Nilotpal
HTTP Status 404 - /SpringMVCUsingRequestParam/WEB-INF/HelloPage.html/India/Nilotpal.jsp
type Status report
**message /SpringMVCUsingRequestParam/WEB-INF/HelloPage.html/India/Nilotpal.jsp**
description The requested resource is not available.
Apache Tom
最後幾行控制檯
NilotpalIndia
In submitRegisterForm
HelloPage
{msg=Congrats!! Form submitted for NilotpalIndia}
這些行是打印在控制器中的行。我可以看到的看法是HelloPage
,但爲什麼它在瀏覽器中以作爲消息消息 /SpringMVCUsingRequestParam/WEB-INF/HelloPage.html/India/Nilotpal.jsp
做
發佈你的控制器不是一個片段。 –
謝謝..編輯後發佈.. – Nilotpal
@ user1233600檢查下面的答案。 –