Servlet 的常见错误总结
- 404错误:资源未找到
原因一:在请求地址中的servlet的别名书写错误。
原因二:虚拟项目名称拼写错误
- 500错误:内部服务器错误
错误一:
java.lang.ClassNotFoundException: com.zxw.servlet.ServletMothod
解决:在web.xml中校验servlet类的全限定路径是否拼写错误。
错误二: 因为service方法体的代码执行错误导致
解决:根据错误提示对service方法体中的代码进行错误更改。
- 405错误:请求方式不支持
原因:请求方式和servlet中的方法不匹配所造成的。
解决:尽量使用 service 方法进行请求处理,并且不要再 service 方法中调用父类的service。
官方API上的描述
https://docs.oracle.com/javaee/7/api/toc.htm
浏览器内查询HttpServletResponse接口即可快速定位
- SC_OK
Status code (200) indicating the request succeeded normally.
状态代码(200)表示请求正常成功。
- SC_NOT_FOUND
Status code (404) indicating that the requested resource is not available.
状态代码(404),指示所请求的资源不可用。
- SC_METHOD_NOT_ALLOWED
Status code (405) indicating that the method specified in the Request-Line is not allowed for the resource identified by the Request-URI.
状态代码(405),指示Request-URI标识的资源不允许在Request-Line中指定的方法。
- SC_INTERNAL_SERVER_ERROR
Status code (500) indicating an error inside the HTTP server which prevented it from fulfilling the request.
状态代码(500),指示HTTP服务器内部的错误,阻止它完成请求。
网友评论