controller 为什么不能跳到本人的jsp页面去 l能查出list有数据

J2EE 码拜 8年前 (2016-05-10) 727次浏览
@Autowired
private StudentService studentService;
//使用注解是映射url的地址,一般使用方法名作为它的url,一个方法对应一个url
@RequestMapping(value=”/queryStudent.action”,method=RequestMethod.GET)
public ModelAndView queryStudent(){
System.out.println(“你好”);
List<Student> studentList=studentService.selectStudent();
System.out.println(“查询出来学生个数:”+studentList.size());
//返回ModeAndView
ModelAndView modelAndView=new ModelAndView();
//相似与一个值栈,jsp界面通过studentList获取值
modelAndView.addObject(“studentList”,studentList);
//指定jsp的路径,假如springmvc.xml视图解析器配置了jsp界面的路径的前缀和后缀
modelAndView.setViewName(“student/students”);
return modelAndView;
}
controller 为什么不能跳到本人的jsp页面去 l能查出list有数据controller 为什么不能跳到本人的jsp页面去 l能查出list有数据
解决方案

10

你的SpringMVC配置文件有设置前缀后缀吗?

<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
		<property name="viewClass"><value>org.springframework.web.servlet.view.JstlView</value></property> 
		<property name="prefix"><value>/WEB-INF/page/</value></property> 
		<property name="suffix"><value>.jsp</value></property>
</bean>

10

<mvc:default-servlet-handler/>

<mvc:annotation-driven/>
也都配置了么?

10

你返回modelandview应该是加一个@responseBody吧

20

/stu…/students   这样写试试

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明controller 为什么不能跳到本人的jsp页面去 l能查出list有数据
喜欢 (0)
[1034331897@qq.com]
分享 (0)