SpringMVC的相关配置:
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="prefix" value="/WEB-INF/views/" />
    <property name="suffix" value=".jsp" />
    <property name="contentType" value="text/html;charset=UTF-8"/>
</bean>
Controller:
@Controller
@RequestMapping("/search/")
public class SolrController {
    @Autowired
    private ItemSolrService service;    @RequestMapping("list.html")
    public String itemList(ItemSolr item,Model model){
        Map<String,String> params = new HashMap<String,String>();
        if(item != null){
            params.put("q", "title:" + item.getTitle());
        }
        List<ItemSolr> itemList = service.queryByMap(params, ItemSolr.class);
        model.addAttribute("itemList", itemList);
        return "item_cat_list";
    }
}
我想要的是跳转到页面将数据显示在html页面上,但实际上把整个jsp页面作为字符串响应了,如下图:有没有人知道原因?求帮助

解决方案 »

  1.   

    原来是在web.xml上配置SpringMVC的DispatcherServlet出了问题
        <servlet>
    <servlet-name>springmvc-web</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <!-- 指定SpringMVC配置文件 -->
    <init-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:spring/servlet-context.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
    <servlet-name>springmvc-web</servlet-name>
    <url-pattern>/*</url-pattern>
    </servlet-mapping>
    将<url-pattern>/*</url-pattern> 改为<url-pattern>/</url-pattern>就好了
    参考http://blog.csdn.net/kaiwii/article/details/7899941
      

  2.   

    你返回的类型是String,又不是视图;当然会将你的页面当成字符串响应
      

  3.   

    我配置了视图解析器InternalResourceViewResolver,返回字符串是可以拼接出视图的url的,我一直都是用这种方式跳转页面