spring mvc,控制器中用RequestMapping,但是能访问?

caobingyi 2018-03-05 01:52:41
控制器里用了@RequestMapping(method = RequestMethod.GET),但是访问的时候不会去执行,而是返回一个值Hello World!
这个值是不存在的
...全文
779 18 打赏 收藏 转发到动态 举报
写回复
用AI写文章
18 条回复
切换为时间正序
请发表友善的回复…
发表回复
教授V5 2018-03-08
  • 打赏
  • 举报
回复
好奇你的 helloword是哪里来的,找到他也许就找到问题所在了
xiongdejun 2018-03-06
  • 打赏
  • 举报
回复
其实你返回的Hello Word 是没有经过Controller的 你看下你的web.xml里是否配置了返回首页面。 至于你想要的功能 你可以在web.xml里过滤这个Controller 然后 @RequestMapping(value="/",method = RequestMethod.GET)就可以了
心随念 2018-03-06
  • 打赏
  • 举报
回复
引用 9 楼 caobingyi 的回复:
[quote=引用 8 楼 u012445835 的回复:] [quote=引用 7 楼 caobingyi 的回复:] 我要访问的地址是:http://127.0.0.1:8080/项目名,然后跳转到enroll.jsp,奇怪的是,我访问http://127.0.0.1:8080/项目名,返回浏览器的是 Hello World! 我知道加value是可以的,但是,我这样的思路不对吗?
这样好像不行的,http://127.0.0.1:8080/项目名 好像默认是进入 index[/quote] 我把index.jsp删除了,还能正常运行,还能返回hello world,怎么回事?[/quote] 你删除之后,按理说没有路径回出现404。还有删除后你在进入你的服务器的wepapp下看看是不是真的删除了。还是删除后,服务器中没有及时更新
  • 打赏
  • 举报
回复
这个Hello world是从哪里来的
小生--幻 2018-03-06
  • 打赏
  • 举报
回复
访问http://127.0.0.1:8080/项目名/试试
yLazL0000 2018-03-05
  • 打赏
  • 举报
回复
引用 5 楼 u012445835 的回复:
[quote=引用 4 楼 caobingyi 的回复:] 代码是这样的,这里不需要value啊 @Controller @RequestMapping("/") public class HelloWorldController { /* * This method will serve as default GET handler. * */ @RequestMapping(method = RequestMethod.GET) public String newRegistration(ModelMap model) { Student student = new Student(); model.addAttribute("student", student); return "enroll"; } }
[/quote] 5楼正解,如@RequestMapping("/test") ,就是http://localhost:8080/项目名/test 你这种就相当于访问http://localhost:8080/项目名
INSISTING2018 2018-03-05
  • 打赏
  • 举报
回复
不知道.我也是刚学完ssm,看到提一下. 还有HelloWord应该是返回页面的内容吧
caobingyi 2018-03-05
  • 打赏
  • 举报
回复
引用 10 楼 INSISTING2018 的回复:
你new的Student对象也没有赋值啊,就是个空的对象
我就是要空对象,不行吗?
INSISTING2018 2018-03-05
  • 打赏
  • 举报
回复
你new的Student对象也没有赋值啊,就是个空的对象
caobingyi 2018-03-05
  • 打赏
  • 举报
回复
引用 8 楼 u012445835 的回复:
[quote=引用 7 楼 caobingyi 的回复:] 我要访问的地址是:http://127.0.0.1:8080/项目名,然后跳转到enroll.jsp,奇怪的是,我访问http://127.0.0.1:8080/项目名,返回浏览器的是 Hello World! 我知道加value是可以的,但是,我这样的思路不对吗?
这样好像不行的,http://127.0.0.1:8080/项目名 好像默认是进入 index[/quote] 我把index.jsp删除了,还能正常运行,还能返回hello world,怎么回事?
心随念 2018-03-05
  • 打赏
  • 举报
回复
引用 7 楼 caobingyi 的回复:
我要访问的地址是:http://127.0.0.1:8080/项目名,然后跳转到enroll.jsp,奇怪的是,我访问http://127.0.0.1:8080/项目名,返回浏览器的是 Hello World! 我知道加value是可以的,但是,我这样的思路不对吗?
这样好像不行的,http://127.0.0.1:8080/项目名 好像默认是进入 index
caobingyi 2018-03-05
  • 打赏
  • 举报
回复
引用 5 楼 u012445835 的回复:
[quote=引用 4 楼 caobingyi 的回复:] 代码是这样的,这里不需要value啊 @Controller @RequestMapping("/") public class HelloWorldController { /* * This method will serve as default GET handler. * */ @RequestMapping(method = RequestMethod.GET) public String newRegistration(ModelMap model) { Student student = new Student(); model.addAttribute("student", student); return "enroll"; } }
[/quote] 如何我要访问的地址是:http://127.0.0.1:8080/项目名 返回的应该是enroll.jsp
caobingyi 2018-03-05
  • 打赏
  • 举报
回复
我要访问的地址是:http://127.0.0.1:8080/项目名,然后跳转到enroll.jsp,奇怪的是,我访问http://127.0.0.1:8080/项目名,返回浏览器的是 Hello World! 我知道加value是可以的,但是,我这样的思路不对吗?
心随念 2018-03-05
  • 打赏
  • 举报
回复



引用 4 楼 caobingyi 的回复:
代码是这样的,这里不需要value啊
@Controller
@RequestMapping("/")
public class HelloWorldController {

/*
* This method will serve as default GET handler.
*
*/
@RequestMapping(method = RequestMethod.GET)
public String newRegistration(ModelMap model) {
Student student = new Student();
model.addAttribute("student", student);
return "enroll";
}
}



caobingyi 2018-03-05
  • 打赏
  • 举报
回复
代码是这样的,这里不需要value啊 @Controller @RequestMapping("/") public class HelloWorldController { /* * This method will serve as default GET handler. * */ @RequestMapping(method = RequestMethod.GET) public String newRegistration(ModelMap model) { Student student = new Student(); model.addAttribute("student", student); return "enroll"; } }
方元之外 2018-03-05
  • 打赏
  • 举报
回复
RequestMapping 你是不是少了个 value 即url
心随念 2018-03-05
  • 打赏
  • 举报
回复
引用 2 楼 fangyuandoit 的回复:
RequestMapping 你是不是少了个 value 即url
2楼说的对,应该是这样的@RequestMapping(value="saveXXX",method = RequestMethod.GET)
caobingyi 2018-03-05
  • 打赏
  • 举报
回复
没有人回答 吗?

81,094

社区成员

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

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