Discuss / Java / 交作业

交作业

Topic source

Dominga丶

#1 Created at ... [Delete] [Delete and Lock User]

出现的错误(上面大佬说过的我就不说了):

1、java.lang.NoClassDefFoundError: org/apache/catalina/WebResourceRoot

解决方法:在pom.xml文件中把tomcat的<scope>标签里面的值改为compile。

2、修改界面,base.xml没有出现以登陆的账号名字

解决方法:GetMapping传入user。

@GetMapping("/update")public ModelAndView update(HttpSession session){   User user = (User) session.getAttribute(KEY_USER);   if (user == null) {      return new ModelAndView("signin.html");   }   return new ModelAndView("update.html", Map.of("user", user));}

修改代码:

@GetMapping("/update")public ModelAndView update(HttpSession session){   User user = (User) session.getAttribute(KEY_USER);   if (user == null) {      return new ModelAndView("signin.html");   }   return new ModelAndView("update.html", Map.of("user", user));}@PostMapping("/update")public ModelAndView doUpdate(@RequestParam("name") String name,HttpSession session){   try{      User user = (User) session.getAttribute(KEY_USER);      if (user !=null){         user.setName(name);         userService.updateUser(user);         return new ModelAndView("redirect:/profile");      }else {         return new ModelAndView("redirect:/signin");      }   }catch (RuntimeException e){      return new ModelAndView("update.html",Map.of("name",name,"error",e));   }}

Loading...

#2 Created at ... [Delete] [Delete and Lock User]

看到你的回复,突然想起一句话,知其然而不知其所以然。

也遇到了你第一个问题,我出现这个错误的原因是先用jdbcTemplate写了一版,然后改成mybatis版,这两版在同一个项目不同包下。,

然后tomcat就报了你第一个错。原因是tomcat没有重新编译。想到了可能是tomcat缓存了。但是我已经把编译完的target文件和生成的tomcat文件夹全删除了也没用。直到看到你这个回复。复制廖大的代码tomcat默认scope是provided,改成compile后重新编译一下就好了。说明我在idea里删除的那个tomcat文件夹根本不是他编译完以后生成的服务器文件夹,,,不知道廖大有没有时间可以给解释一下.


  • 1

Reply