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));   }}

  • 1

Reply