Springmvc不进入Controller导致404

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/qq_36355271/article/details/88578606

出现这种情况  会有很大情况,首先请检查各项配置是否都有,然后检查各项配置对应的文件路径是否正确,然而一切都正确(我就是),网上查好久发现 <a href="message/go"> 中message前不加斜杠  ,

          我之前的写法  <a href="/message/go">点我,有惊喜</a>   好坑有没有

 

<html>
<body>
<h2>Hello World!</h2>
<a href="message/go">点我,有惊喜</a>
</body>
</html>

 

@Controller
@RequestMapping("/message")
public class messageController {

    @RequestMapping("/go")
    public String getTest(){
        System.out.print("reach");
        return "reach";
    }
}
展开阅读全文

SpringMVC 无法进入controller 出现404

07-02

一个简单的 基于注解的 springmvc项目测试rn项目结构:rn[img=https://img-bbs.csdn.net/upload/201907/02/1562064709_904428.png][/img]rnrnrn下面是主要文件, 控制台也没报错,网上看到很多类似的错误,但是该来该去还是404 求助大佬们!rn=======================================================================rnweb.xml :rnrnrnrn rn rn contextConfigLocation rn classpath:springmvc-config.xmlrn rnrn rn org.springframework.web.context.ContextLoaderListenerrn rn rn rn rn springmvcrn rn org.springframework.web.servlet.DispatcherServlet rn rn rn rn rn rn contextConfigLocationrn classpath:springmvc-config.xmlrn rn rn 1rn rn rn rn rn springmvcrn / rn rn rnrn=======================================================================rnspringmvc-config.xml :rnrnrn rn rn rn rn rn rn rn rn rn rn rnrnrnrn=======================================================================rnFirstController .java:rnrnpackage com.itheima.controller;rnrnimport javax.servlet.http.HttpServletRequest;rnimport javax.servlet.http.HttpServletResponse;rnimport org.springframework.stereotype.Controller;rnimport org.springframework.ui.Model; rnimport org.springframework.web.bind.annotation.RequestMapping;rn/**rn * 控制器rn * */rn@Controllerrn@RequestMapping(value="/hello")rnpublic class FirstController rn // handleRequestO是 Controller 接口的实现方法, rn //调用 该方法来处理请求,并返回一个包含视图名或包含视图名和模型的 ModelAndView 对象。 rn @RequestMapping(value="/firstController") rn public String handleRequest(HttpServletRequest request,rn HttpServletResponse response, Model model) throws Exception rn System.out.println("向模型对象中添加数据");rn //向模型对象中添加数据rn model.addAttribute("msg","这是我的第一个mvc程序");rn System.out.println("向模型对象中添加数据");rn rn return "first.jsp";rn rnrnrn=======================================================================rnfirst.jsp:rnrn<%@ page language="java" contentType="text/html; charset=utf-8"rn pageEncoding="utf-8"%>rnrnrnrn rn Insert title herernrnrn $msgrnrnrnrn 论坛

SpringMVC进不了controller,页面404

05-20

[b]小白刚刚接触springmvc不久,发现无法进入我对应的action,一直报404错误,各位大神帮帮忙啊~~rnrnweb.xml[/b]rn rn rn contextConfigLocationrn /WEB-INF/config/spring/applicationContext-*.xmlrn rn rn org.springframework.web.context.ContextLoaderListenerrn rn rn rn rn springMVCrn org.springframework.web.servlet.DispatcherServletrn rn contextConfigLocationrn /WEB-INF/config/spring/springmvc.xmlrn rn rn rn springMVCrn *.actionrn rn rn rn rn CharacterEncodingFilterrn org.springframework.web.filter.CharacterEncodingFilterrn rn encodingrn utf-8rn rn rn rn CharacterEncodingFilterrn /*rn rnrn[b]springmvc.xml[/b]rn rn rn rn rn rn rn rnrn rn rn rn rn rn rn rn rn rn rn rn rn 5242880rn rn rn rn[b]usercontroller[/b]rnrn@Controllerrnrnpublic class UserController rn rn @Autowiredrn private UserService userService;rn rn public UserService getUserService() rn return userService;rn rnrn public void setUserService(UserService userService) rn this.userService = userService;rn rn rn @RequestMapping("/login.action")rn public String acceptLoginRequest(User user,HttpServletRequest request)rn boolean result = userService.validateLogin(user);rn if(result)rn request.getSession().setAttribute("user_name", user.getUser_name());rn return "backstage/index";rn elsern request.setAttribute("loginError", 1);rn return "backstage/login";rn rn rn rn @RequestMapping("/Taste/register.action")rn public String acceptRegisterRequest(User user,HttpServletRequest request)rn System.out.println("coming in....");rn try rn rn userService.register(user);rn request.setAttribute("registerLog", "成功");rn return "backstage/login";rn catch (Exception e) rn request.setAttribute("registerLog", "失败");rn return "backstage/reg";rn rn 论坛

SpringMVCController跳转问题

04-15

[color=#FF0000]今天在写SSM框架搭建的项目时遇到的问题,请各位大佬不吝赐教,[/color]rn[color=#FF0000]rn首先,这是我的第一个Controller类:[/color]rnrnpackage com.cms.controller;rnrn/**rn * 页面展示controllerrn */rnrn@Controllerrnpublic class PageController rnrn @RequestMapping("/")rn public String showIndex() rn return "/admin/index";rnrnrn @RequestMapping("/page")rn public String showPage(@PathVariable String page) rn return "/admin/"+page;rnrnrnrnrn[color=#FF0000]然后,这是我的第二个Controller类:(只显示一部分,其他方法跟这个没多大联系)[/color]rn@Controllerrnpublic class CommunityController rn@RequestMapping("/cummunity/edit/comId")rn@ResponseBodyrnpublic String editCommunity(@PathVariable Long comId, Model model) throws Exception rn CmCommunity community = communityService.getCommunityByComId(comId);rnmodel.addAttribute("community",community);rn return "communityedit";rnrnrnrn[color=#FF0000]再次,这是我未完成的项目结构视图:[/color]rnrn[img=https://img-bbs.csdn.net/upload/201804/15/1523797879_496871.png][/img]rnrn[color=#FF0000]还有springMVC.xml中视图解析器我是这样配置的:[/color]rn[img=https://img-bbs.csdn.net/upload/201804/15/1523797894_571042.png][/img]rnrn[color=#FF0000]下面是我的jsp页面a标签中的设置:[/color]rn (后面的数字是用来进行查询的某个id号)rn[color=#FF0000]最后的运行结果是这样子的:[/color]rn[img=https://img-bbs.csdn.net/upload/201804/15/1523797907_448707.png][/img]rn[color=#FF0000]请问各位该如何改?[/color] 论坛

没有更多推荐了,返回首页