找到tomcat路径中conf文件夹下server.xml文件找到

<Host name="localhost"  appBase="webapps"
            unpackWARs="true" autoDeploy="true">

<Host name="localhost" appBase="/xxx/xxx/xxx/xxx/webapps"
unpackWARs="true" autoDeploy="true">
<Context docBase="/xxx/xxx/xxx/wxs_home" path="" debug="0" reloadable="true" crossContext="true"/>

说明:/xxx/xxx/xxx/xxx/webapps修改的项目默认路径  /xxx/xxx/xxx/wxs_home 修改的默认项目,放入自定义的首页index.jsp/index.html ;顺便放入错误提示页面error.jsp

错误提示页面:

error.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>xxx错误</title>
</head>
	哎哟喂!您乘坐的这条“程序”违反了tomcat规则!请稍后访问......
</body>
</html>

找到tomcat路径中conf文件夹下web.xml文件找到

<welcome-file-list>
        <welcome-file>index.html</welcome-file>
        <welcome-file>index.htm</welcome-file>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>

在下面添加

<!-- 400错误 -->
	<error-page>
		<error-code>400</error-code>
		<location>/error.jsp</location>
	</error-page>
	<!-- 404 页面不存在错误 -->
	<error-page>
		<error-code>404</error-code>
		<location>/error.jsp</location>
	</error-page>
	<!-- 500 服务器内部错误 -->
	<error-page>
		<error-code>500</error-code>
		<location>/error.jsp</location>
	</error-page>
	<!-- java.lang.Exception异常错误,依据这个标记可定义多个类似错误提示 -->
	<error-page>
		<exception-type>java.lang.Exception</exception-type>
		<location>/error.jsp</location>
	</error-page>
	<!-- java.lang.NullPointerException异常错误,依据这个标记可定义多个类似错误提示 -->
	<error-page>
		<exception-type>java.lang.NullPointerException</exception-type>
		<location>/error.jsp</location>
	</error-page>
	<error-page>
		<exception-type>javax.servlet.ServletException</exception-type>
		<location>/error.jsp</location>
	</error-page>

重启tomcat服务器,默认项目http://xxx.xxxxxx.xxx; 400/404/500类型的错误页面:http://xxx.xxxxxx.xxx/error.jsp

Tomcat404/500 错误,自定义错误页面 当服务器出现404500错误时候希望能够给用户友好的现实界面 只需要在项目web.xml中添加一些配置 &lt;!-- 400错误 --&gt; &lt;error-page&gt; &lt;error-code&gt;400&lt;/error-code&gt; &lt;location&gt;/error.jsp&... 说明:/xxx/xxx/xxx/xxx/webapps修改项目默认路径/xxx/xxx/xxx/wxs_home 修改默认项目,放入自定义的首页index.jsp/index.html ;顺便放入错误提示页面error.jsp 错误提示页面: error.jsp <%@ page language="java" contentTy 编写新的界面error.html,将此界面放到 tomcat6/webapps/ROOT 目录下 2、创建编写web.xml 修改TomcatwebappsROOTWEB-INFweb.xml文件内容,指定错误状态码对应的界面 <?xml version="1.0" encoding="utf-8"?> <web-app xmlns="http://java.sun.com/xml/n
tomca 400 错误 在请求目标中无法找到有效字符,有效字符在RFC 7203和 RFC 3986中定义 Invalid character found in the request target. The valid characters are defined in RFC 7230 and RFC 3986 org.apache.coyote.http11.Http11InputBuffer.parseRequestLine(Http11InputBuffer.java:503)
Tomcat 400报错显示tomcat信息,这就存在着很大的安全隐患。 根据官网给出的方案需要重写ErrorReportValve处理400错误跳转到自定义页面,首先需要更改tomcat中的server.xml文件,在host中添加Valve,页面将不显示错误的详细信息。 <Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true"> <Valve className...
在做javaweb项目时,关于统一错误页面在开发的过程中就做过编码,并且一直都很有效,像500,404,403等常规错误码都能得到有效处理,但是400却不行,而且还暴露tomcat的版本信息,这是很严重的安全漏洞 解决方法百度和测试很多,总结如下: 问题产生: 根据rfc规范,url中不允许有 |,{,}等特殊字符,但在实际生产中还是有些url有可能携带有这些字符,特别是|还是较为常见的。在tomcat升级到7以后,对url字符的检查都变严格了,如果出现这类字符,服务器tomcat将直接返回400状态码。
Invalid character found in the request target. The valid characters are defined in RFC 7230 and RFC 3986 新版本的tomcat对url的参数做了比较规范的限制,必须按照RFC 7230 and RFC 3986规范,对于非保留字字符,如果不做转义处理,一律都会报The valid characters are defined in RFC 7230 and RFC 3986 错误。 org.apache