RequestMapping一添加headers就报404

Alaska_Lee 2016-01-15 11:10:01

@Controller
@RequestMapping("hello")
public class App
{
@RequestMapping(value="/getkey",
method=RequestMethod.GET,
//headers="Accept=text/plain",
produces="text/plain;charset=utf-8"
)
public @ResponseBody String getKey(@RequestParam String key){
return getValue(key);
}
}


把headers="Accept=text/plain",注释掉就能正常访问。求问这是何解啊?

配置文件:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">

<!-- 对包中的所有类进行扫描,以完成Bean创建和自动依赖注入的功能 稍后会创建该包:webmvct.cmd -->
<context:component-scan base-package="com.TYYJ"/>


<!-- 定义Spring MVC 的模板文件 -->
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/> <!-- 支持JSTL -->
<property name="prefix" value="/WEB-INF/jsp/" /> <!-- 模板的路径 -->
<property name="suffix" value=".jsp" /> <!-- 模板文件的后缀-->
</bean>

</beans>
...全文
433 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
scmod 2016-01-21
  • 打赏
  • 举报
回复
引用 4 楼 lijie19871108 的回复:
[quote=引用 2 楼 scmod 的回复:] 原本你发请求带来的request headers里面有Accept=text/plain这段么...
produces里面也有这段,如果request header里面没有,应该也访问不了啊 是不是produces和headers里面都有text/plain,重复了的原因 [/quote] 不知道...我好像从来没用过headers跟produces参数...
Alaska_Lee 2016-01-21
  • 打赏
  • 举报
回复
引用 2 楼 scmod 的回复:
原本你发请求带来的request headers里面有Accept=text/plain这段么...
produces里面也有这段,如果request header里面没有,应该也访问不了啊 是不是produces和headers里面都有text/plain,重复了的原因
Alaska_Lee 2016-01-21
  • 打赏
  • 举报
回复
引用 1 楼 BatteyBay 的回复:
你的getKey方法,回去Key的@RequestParam写错了。。。。应该是@RequestParams(“key”) String key,,,,才能拿到值
和这个应该没有关系
牙买加Max 2016-01-15
  • 打赏
  • 举报
回复
你的getKey方法,回去Key的@RequestParam写错了。。。。应该是@RequestParams(“key”) String key,,,,才能拿到值
scmod 2016-01-15
  • 打赏
  • 举报
回复
原本你发请求带来的request headers里面有Accept=text/plain这段么...

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧