我直接在PatternServlet中绑定了URL而没有在web.xml文件中写
来源:6-1 JSP九大内置对象
xxxxxxb
2020-01-01 19:17:23
为什么页面没有报500的错误而显示的其他同事?
@WebServlet("/pattern/*")
public class PatternServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public PatternServlet() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String url = request.getRequestURL().toString();
System.out.println(url);
String id = url.substring(url.lastIndexOf("/")+1);
System.out.println(id);
response.setContentType("text/html;charset=utf-8");
PrintWriter out = response.getWriter();
if(id.equals("1")) {
out.println("张三");
}else if(id.equals("2")) {
out.println("李四");
}else{
out.println("其他员工");
}
}
}
====================================
<%@page contextType="text/html;charset=utf-8" isErrorPage="true"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
服务器内部错误,请联系管理员,错误信息如下:
<%
String mes = exception.getMessage();
out.println("<br>"+mes);
%>
</body>
</html>
=================================
<context-param>
<param-name>copyright</param-name>
<param-value>© 2020 imooc.com 京ICP备 12003892号-11</param-value>
</context-param>
<context-param>
<param-name>title</param-name>
<param-value>慕课网-程序员的梦工厂</param-value>
</context-param>
<!-- 制定错误页面 -->
<error-page>
<error-code>404</error-code>
<location>/error/404.html</location>
</error-page>
<error-page>
<error-code>500</error-code>
<location>/error/500.jsp</location>
</error-page>
</web-app>
2回答
同学的问题是解决了,是吗?继续加油。
祝:学习愉快~
xxxxxxb
提问者
2020-01-01
这是显示信息
相似问题