404错误

来源:2-5 自由编程

复java_n

2021-04-29 17:31:33

http://img.mukewang.com/climg/608a7c6f096b08c223791294.jpg

http://img.mukewang.com/climg/608a7c8109e2603614620610.jpghttp://img.mukewang.com/climg/608a7c93094f0a7e09270695.jpg

http://img.mukewang.com/climg/608a7cab09857e4721180737.jpg

http://img.mukewang.com/climg/608a7cd709ebb1ca09891185.jpghttp://img.mukewang.com/climg/608a7cc109e0dbe815121084.jpg

package com.imooc.springmvc;

import com.imooc.springmvc.entity.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class Testcontroller {
@PostMapping("/t")
@ResponseBody
   public String postTest(User user) {
return  "<fieldset><legend>登陆成功</legend>用户名:" +user.getUsername()+

"<br>密码:"+user.getPassword()+"</fieldset>";
}
}
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Title</title>
</head>
<body>
<form action="/t" method="post">
<input name="username">
<input name="password">
<input type="submit" value="提交">
</form>
</body>
</html>


写回答

1回答

好帮手慕阿园

2021-04-29

同学你好,测试代码直接http://localhost:8080/t是会出现405异常,如下

http://img.mukewang.com/climg/608a815509f52b6704860203.jpg

同学查看下控制台是否报错,tomcat是否启动成功,如果启动成功,同学看看jsp页面能否正常访问,如果可以建议同学访问jsp页面,点击提交后看看能否正常跳转

http://img.mukewang.com/climg/608a822209812c3c04520083.jpg

另外查看同学贴出的图片也没有问题,建议同学将out目录和target目录删除后重新构建下项目试试

如果还存在问题,同学试试下载源码,将代码复制粘贴到源码中看看能否正常运行

​祝学习愉快~

0

0 学习 · 8263 问题

查看课程