Tomcat发生错误时跳转到错误页面
一、修改 tomcat 的配置文件
修改 tomcat 的配置文件,当页面发生错误时跳转到指定的页面,在 tomcat 中 web.xml 文件中添加如下内容:
<error-page>
<error-code>400</error-code>
<location>/error.html</location>
</error-page>
<error-page>
<error-code>404</error-code>
<location>/error.html</location>
</error-page>
<error-page>
<error-code>500</error-code>
<location>/error.html</location>
</error-page>
<error-page>
<exception-type>java.lang.Exception</exception-type>
<location>/error.html</location>
</error-page>
<error-page>
<exception-type>java.lang.NullPointerException</exception-type>
<location>/error.html</location>
</error-page>
二、编写 error.html 界面
error.html 界面需要放在 webapps 的 ROOT 目录中,结构如下:
404文件夹内容
error.html
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"><head>
<title>网页访问不了</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="stylesheet" type="text/css" href="404/error_all.css?t=201303212934">
</head>
<body class="error-404">
<div id="doc_main">
<section class="bd clearfix">
<div class="module-error">
<div class="error-main clearfix">
<div class="label"></div>
<div class="info">
<h3 class="title">啊哦,你所访问的页面不存在了,可能是炸了</h3>
<div class="reason">
<p>可能的原因:</p>
<p>1.手抖打错了。</p>
<p>2.链接过了保质期。</p>
</div>
<div class="oper">
<p><a href="javascript:history.go(-1);">返回上一级页面></a></p>
</div>
</div>
</div>
</div>
</section>
</div>
</body></html>
error_all.css
body, div, dl, dt, dd, ul, ol, li, h1, h2, h3, h4, h5, h6, pre, code, form, textarea, select, optgroup, option, fieldset, legend, p, blockquote, th, td {
margin:0;
padding:0
fieldset, img {
border:0
ul, li, ol {
list-style:none
h1, h2, h3, h4, h5, h6 {
font-size:100%
legend {
color:#000
input, button, textarea, select, optgroup, option {
font-family:inherit;
font-size:inherit;
font-style:inherit;
font-weight:inherit
input, button, select {
margin:0;
*font-size:100%;
line-height:1.2
a img, img {
-ms-interpolation-mode:bicubic
body {
background:#FFF
color:#06c;
text-decoration:none
a:hover, a:active, a:focus {
color:#06c;
text-decoration:underline
table {
border-collapse:collapse;
border-spacing:0
header, aside, section {
display:block
body, button, input, select, textarea {
font:12px/1.5 tahoma, arial, "微软雅黑";
color:#666
.center {
text-align:center
.clear:after, .clearfix:after {
content:".";
display:block;
clear:both;
visibility:hidden;
font-size:0;
height:0;
line-height:0
.clear, .clearfix {
zoom:1
.b-panel {
position:absolute
.b-fr {
float:right
.b-fl {
float:left
.error-404 {
background-color:#EDEDF0
.module-error {
margin-top:182px
.module-error .error-main {
margin:0 auto;
width:420px
.module-error .label {
float:left;
width:160px;
height:151px;
background:url('error.png') 0 0 no-repeat
.module-error .info {
margin-left:182px;
line-height:1.8
.module-error .title {
color:#666;
font-size:14px
.module-error .reason {
margin:8px 0 18px 0;
color:#666
error.png
Tomcat发生错误时跳转到错误页面一、修改 tomcat 的配置文件修改 tomcat 的配置文件,当页面发生错误时跳转到指定的页面,在 tomcat 中 web.xml 文件中添加如下内容:&amp;amp;lt;!-- 400错误 --&amp;amp;gt; &amp;amp;lt;error-page&amp;amp;gt; &amp;amp;lt;error-code&amp;amp;gt;400&amp;amp
使用 apache 和 tomcat 配置一个可以应用的 web 网站,要达到以下要求:
1、 Apache 做为 HttpServer ,后面连接多个 tomcat 应用实例,并进行负载均衡。
2、 为系统设定 Session 超时时间,包括 Apache 和 tomcat
3、 为系统屏蔽文件列表,包括 Apache 和 tomcat
注:本例程以一台机器为例子,即同一台机器上装一个apache和4个Tomcat。
一、 前期准备工作:安装用的程序(前提保证已安装了JDK1.5以上的版本)
jdk1.6.0_18下载:
http://java.sun.com/javase/downloads/index.jsp
APAHCE 2.2.14下载:apache_2.2.14-win32-x86-no_ssl.msi http://httpd.apache.org/download.cgi下载
TOMCAT6.0.20下载:apache-tomcat-6.0.20.zip直接解压。http://tomcat.apache.org/download-60.cgi
Jdk安装目录下D:\toots\Java\jdk1.6.0_18\bin\msvcr71.dll复制到C:\WINDOWS\system32下
二、 安装过程
设置环境变量:
JAVA_HOME= D:\toots\Java\jdk1.6.0_18
classpath=.;%JAVA_HOME%\lib\dt.jar;%JAVA_HOME%\lib\tools.jar;(.;一定不能少,因为它代表当前路径)
path=%JAVA_HOME%\bin
APAHCE安装目录:D:\toots\Apache下
四个TOMCAT目录:自行解压到(D:\toots\)下。分别为 tomcatA,tomcatB,tomcatC,tomcatD
三、配置
1、Apache配置
1.1、httpd.conf配置
修改APACHE的配置文件D:\toots\Apache \conf\httpd.conf
将以下Module的注释去掉,这里并没有使用mod_jk.so进行apache和tomcat的链接,从2.X以后apache自身已集成了mod_jk.so的功能。只需简单的把下面几行去掉注释,就相当于以前用mod_jk.so比较繁琐的配置了。这里主要采用了代理的方法,就这么简单。
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_connect_module modules/mod_proxy_connect.so
LoadModule proxy_ftp_module modules/mod_proxy_ftp.so
LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule proxy_ajp_module modules/mod_proxy_ajp.so
LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
再找到<IfModule dir_module></IfModule>加上index.jsp修改成
<IfModule dir_module>
DirectoryIndex index.html index.jsp
</IfModule>
1.1.1、 在最下面加入
ProxyRequests Off
<proxy balancer://cluster>
BalancerMember ajp://127.0.0.1:9001 loadfactor=1 route=jvm1
BalancerMember ajp://127.0.0.1:9002 loadfactor=1 route=jvm2
BalancerMember ajp://127.0.0.1:9003 loadfactor=1 route=jvm3
BalancerMember ajp://127.0.0.1:9004 loadfactor=1 route=jvm4
<proxy >
上面的四个BalancerMember成员是我们配置的tomcat集群。后面会说明的
1.2、httpd-vhosts.conf设置
接下来进行虚拟主机的设置。APACHE的虚拟主机设置如下:
首先要修改 conf/httpd.conf找到
(#Include conf/extra/httpd-vhosts.conf)把注释去掉。
# Virtual hosts
Include conf/extra/httpd-vhosts.conf
在文件(D:/toots/Apache/conf/extra/httpd-vhosts.conf)最下面加入
<VirtualHost *:80>
ServerAdmin rosi@126.com
DocumentRoot "D:/toots/Apache/docs/dummy-host3.localhost"//你的安装目录
ServerName localhost//服务名(域名)
ServerAlias localhost//服务别名
ProxyPass / balancer://cluster/ stickysession=jsessionid nofailover=On
ProxyPassReverse / balancer://cluster/
</VirtualHost>
其中的域名和路径根据你自己情况设置
然后再设置TOMCAT虚拟主机
2 配置 tomcat
2.1. 配置 server 的关闭
我们需要在一台机器上跑 4 个不同的 tomcat ,需要修改不同的 tomcat 的关闭口,避免出现端口被占用的情况。在
TomcatA\conf,
TomcatB\conf,
TomcatC\conf下和
TomcatD\conf下的 server.xml 中找到 server, 将:
<Server port="8005" shutdown="SHUTDOWN">
<Server port="XXXX" shutdown="SHUTDOWN">
XXXX 在这里表示不同的端口:我的其它四个 tomcat 分别使用 9006,9007,9008 , 9009
2.2. 配置 Engine
把原来的配置注释掉,把下面一句去掉注释。并标明jvmRoute="jvm2".
<Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm2">
以下是原来的配置。
<!-- <Engine name="Catalina" defaultHost="localhost"> -->
其他(tomcat6.02和tomcat6.03)也要同样 配置。注意:jvmRoute配置不要一样。
<Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm3">
<Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm4">
2.3. 配置 Connector
原来的默认配置。
<!-- Define an AJP 1.3 Connector on port 8009 -->
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
这里是apache和tomcat链接的关键,前台apache就是通过AJP协议与tomcat进行通信的,以完成负载均衡的作用。也可以用HTTP协议。大家注意它们是如何连接通信的,上面的红色部分(port="8009")就是连接的接口了。
把四个tomcat的<Connector port="XXX" />port分别改成与上面
<proxy balancer://cluster>
#与tomcatA对应,route与<Engine jvmRoute="jvm1">对应。
BalancerMember ajp://127.0.0.1:9001 loadfactor=1 route=jvm1
#与tomcatB对应,route与<Engine jvmRoute="jvm2">对应。
BalancerMember ajp:// 127.0.0.1:9002 loadfactor=1 route=jvm2
#与tomcatC对应,route与<Engine jvmRoute="jvm3">对应。
BalancerMember ajp:// 127.0.0.1:9003 loadfactor=1 route=jvm3
#与tomcatD对应,route与<Engine jvmRoute="jvm4">对应。
BalancerMember ajp:// 127.0.0.1:9004 loadfactor=1 route=jvm4
</proxy>
中的端口对应,
tomcatA改为 <Connector port="9001" protocol="AJP/1.3" redirectPort="8441" />
.tomcatB改为 <Connector port="9002" protocol="AJP/1.3" redirectPort="8442" />
tomcatC改为 <Connector port="9003" protocol="AJP/1.3" redirectPort="8443" />
tomcatD改为 <Connector port="9004" protocol="AJP/1.3" redirectPort="8444" />
<Connector executor="tomcatThreadPool"
port="8081" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="9441" />
<Connector executor="tomcatThreadPool"
port="8082" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="9442" />
<Connector executor="tomcatThreadPool"
port="8083" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="9443" />
<Connector executor="tomcatThreadPool"
port="8084" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="9444" />
一定要与上面的一致。同时也要把redirectPort的值改成唯一的,确保四个tomcat的都不一样。
2.4.配置Cluster(每个tomcat中都要修改)
原来的配置。
<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
修改为以下的代码:<Receiver port=”XX”/>port也要保证唯一性,
tomcatA改为 <Receiver port="5001"
.tomcatB改为 <Receiver port="5002"
tomcatC改为<Receiver port="5003"
tomcatD改为 <Receiver port="5004"
确保四个tomcat的都不一样。以下是tomcatA的内容红色部分,分别是5001,5002,5003,5004.
<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster" channelSendOptions="6">
<Manager className="org.apache.catalina.ha.session.BackupManager"
expireSessionsOnShutdown="false"
notifyListenersOnReplication="true"
mapSendOptions="6"/>
<Manager className="org.apache.catalina.ha.session.DeltaManager"
expireSessionsOnShutdown="false"
notifyListenersOnReplication="true"/>
<Channel className="org.apache.catalina.tribes.group.GroupChannel">
<Membership className="org.apache.catalina.tribes.membership.McastService"
address="228.0.0.4"
port="45564"
frequency="500"
dropTime="3000"/>
<Receiver className="org.apache.catalina.tribes.transport.nio.NioReceiver"
address="auto"
port="5001"
selectorTimeout="100"
maxThreads="6"/>
<Sender className="org.apache.catalina.tribes.transport.ReplicationTransmitter">
<Transport className="org.apache.catalina.tribes.transport.nio.PooledParallelSender"/>
</Sender>
<Interceptor className="org.apache.catalina.tribes.group.interceptors.TcpFailureDetector"/>
<Interceptor className="org.apache.catalina.tribes.group.interceptors.MessageDispatch15Interceptor"/>
<Interceptor className="org.apache.catalina.tribes.group.interceptors.ThroughputInterceptor"/>
</Channel>
<Valve className="org.apache.catalina.ha.tcp.ReplicationValve"
filter=".*\.gif;.*\.js;.*\.jpg;.*\.png;.*\.htm;.*\.html;.*\.css;.*\.txt;"/>
<Deployer className="org.apache.catalina.ha.deploy.FarmWarDeployer"
tempDir="/tmp/war-temp/"
deployDir="/tmp/war-deploy/"
watchDir="/tmp/war-listen/"
watchEnabled="false"/>
<ClusterListener className="org.apache.catalina.ha.session.ClusterSessionListener"/>
</Cluster>
这个设置是主要用以tomcat的集群。
把解压缩版的tomcat6注册成服务并设置自启动
当然,这样注册出来的服务启动类型是手动的,如果想设置为开机自动启动,则需要修改
注册服务自启动:
bin目录下的service.bat文件
打开此文件,在倒数第三行左右的那句输出
echo The service '%SERVICE_NAME%' has been installed.
这句是输出服务安装成功,在这之前加一句
sc config %SERVICE_NAME% start= auto
就OK了,以后开机后tomcat服务就自动启动了
注册服务:
首先,在开始->运行中敲cmd,进入MS-DOS界面
cd 到tomcat的bin目录下
运行命令service install TomcatA
就可以把tomcat注册成系统服务了,服务的名称是TomcatA
删除服务运行
service uninstall TomcatA 就可以了
四、启动服务,测试tomcat自带的例子
1、测试apache和tomcat协作。
先在每个tomcat中的\webapps\ROOT下的index.jsp下面加上以下的测试代码部分:(X代表不同的tomcat的输出不同的信息),把index.html删除,以免影响测试效果。在最后面的加上.即</table></body>之间。
System.out.println("tomcat6.0X deal with request");
然后再通过http://localhost来访问一下,就会出现大家熟悉的猫猫。
然后再通过分别访问
http:// 127.0.0.1:8081,
http:// 127.0.0.1:8082,
http:// 127.0.0.1:8083,
http:// 127.0.0.1:8084
它们访问的内容和上面的http:// 127.0.0.1是一样的。
这样就说明apache和TOMCAT整合成功!
这样就说明apache和TOMCAT整合成功!
2、测试均衡器
通过http:// 127.0.0.1多次访问,要想看到真正的效果,必须用一些压力测试工具,可用微软Microsoft Web Application Stress Tool进行简单压力测试,不然你靠不停刷新是体现不出来的,你只会在一个tomcat的控制台有输出结果。只用用压力测试工具模拟大量用户同时访问,你会发现四个tomcat控制台均有打出控制信息,说明均衡器工作正常。
3、测试Session复制
访问url: http://localhost/examples/servlet/SessionExample 可以得到一个关于session的例子,我们用它来测试集群的错误恢复能力。
测试步骤如下:
关闭tomcat1和tomcat2;
启动tomcat1
在浏览器中输入属性名tomcat1和属性值tomcat1再提交,返回的页面显示session中有刚刚输入的tomcat1属性;
启动tomcat2;
过一会后(等待tomcat2和tomcat1通信并复制信息)关闭tomcat1;
在浏览器中输入属性名tomcat2和属性值tomcat2再提交,返回的页面显示session中有刚刚输入的tomcat2属性,还有先前输入的tomcat1属性;
启动tomcat1;
过一会后(等待tomcat2和tomcat1通信并复制信息)关闭tomcat2;
在浏览器中输入属性名tomcat11和属性值tomcat11再提交,返回的页面显示session中有刚刚输入的tomcat11属性,还有先前输入的tomcat1和tomcat2属性;
域名绑定与虚拟目录设置:
server.xml 的修改方式如下:
(一)多域名绑定
2.接下来就是重点了哈哈...
单个域名绑定:
<Engine name="Catalina" defaultHost="localhost">
<Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false" />
</Engine>
当然这里我把注释代码统统删除掉了,省的碍眼
<Host name="chengqun.202.71one.com" debug="0" appBase="webapps"
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">
<Context path="/" docBase="d:\wwwroot\chengqun"></Context>
</Host>
<Host name="chengqun1.202.71one.com" debug="0" appBase=" webapps"
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">
<Context path="/" docBase="d:\wwwroot\chengqun1"></Context>
</Host>
多域名绑定:
<Host name="chengqun.202.71one.com" debug="0" appBase="webapps"
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">
<Alias>chengqun.202.71one.com</Alias>
<Alias>chengqun1.202.71one.com</Alias>
<Alias>chengqun2.202.71one.com</Alias>
<Context path="/" docBase="d:\ EDirectSalesroot "></Context>
</Host>
虚拟目录d:\ EDirectSalesroot的目录下建立WEB-INF 目录,再将…Tomcat 6.0\webapps\ROOT\WEB-INF 目录中的web.xml 文件拷贝到虚拟目录下建立WEB-INF 子目录中.
OpenASP是一款使用java实现的asp服务器(asp server),实用Tomcat7和asp2jsp改造整合而来,利用JavaCC实现了对ASP语法的解析。
OpenASP 1.0.0 更新内容:
1.修正了VB解析的bug;
2.修正了tomcat资源载入错误的bug;
3.修正了tomcat配置文件载入失败的bug;
4.修正了tomcat读取xml文件核心错误。
真正实现第一个OpenASP的可用版本!
编译版本如何使用:
1.安装jdk1.7,并配置好环境变量;
2.下载并解压压缩包到[安装目录];
3.双击执行[安装目录]/bin/startup.bat
这一步如果不出错的话,应该会打开一个cmd窗口一直运行(不要关闭此窗口)
4.打开浏览器,输入http://localhost:8080/查看运行结果
如果见到欢迎界面,表示系统已经运行起来了
要测试asp仅需将asp文件拷贝至[安装目录]/webapps/ROOT/下即可。
执行日志视图,查看谁运行什么脚本以及何时运行您的脚本也可以登录到此视图
使用已配置的SMTP设置从脚本发送电子邮件
GroovyServer捆绑了Twilio API 通过脚本发送短信或语音消息
通过内置的帮助程序API轻松创建CSV报告
对于按需执行的脚本: 利用ZKOSS框架UI组件
运行时要求用户输入
1.无法添加依赖
2.执行逆向生成操作的 Maven 命令 命令:mybatis-generator:generate。 报错执行不了
3. The import org.springframework.test cannot be resolved 无法导包
4. 运行Junit测试报错java.io.FileNotFoundException: class path resource [mybatis-config.xml] cannot be opened because it:java.io.FileNotFoundException: class path resource [mybatis-config.xml] cannot be opened because it
5.B站看视频如果声音嘈杂,不清楚,小。右键,点击清澈人声。有时候弹幕真牛逼。
6. 看视频第30集,日志系统操作,测试日志时候添加类报错:LoggerFactory cannot be resolved
7,查错需要看控制台的Caused by:后边的内容。
8,测试testTx()报错3,是因为,缺少1这句话。
9. Eclipse如何还原和重置窗口布局复位是reset
10.idea缺少maven导航条
11.idea运行项目,报错404,基本都是Tomcat配置那里两个路劲配置不一致导致的。
12.问题未解决!!!45集测试ssm环境整合,跑不起来
13 将项目转移到idea中运行,并且进行一些配置修改,将以上12问题解决!
14.更改配置文件,或者有其他更改,最好要在build那里rebuild一下,要不然可能会出一些莫名其妙的错误,这是在用renrenfast框架时候,增加学生,教师等模块,界面一致装,不能正常显示,梦圆教我的。Rebuild后,再重启,即可解决问题。
15.idea加载一个新项目,第一需要调出右侧maven导航条,更新下maven,第二需要在artifact那边的lib里增加maven依赖。这样才能保证依赖和包齐全,项目才能正常运行。这是狂神教的
16.eclipse里边的project相当于idea里边的module。
17. idea 光标变粗如何恢复
18.出现问题:视频63集,无法做出和他一样的页面,HTML变红报错,网页没有按钮
19. 69集管理员登录测试,报400错误
20 问题19的启发,看视频遇到问题的话,那就载看一遍,很有可能是哪里敲错了,导致了问题的出现,好好再检查一遍流程,很多问题基本能够解决。
21 IDEa中Ctrl+f 是在当前这个页面搜索任何想找的代码
22. 70集管理员登录,重定向,报错404
23.最开始这边的弹框弹不出来
24.视频82集,页面显示主体数据,运行项目后,等录出错,出现空白页,控制台也有报错
25.点击用户维护,不想老师那样,出现tom相关信息,button按钮也有问题
26.第87集分页导航条查询有问题
27,95集新增功能,点击页面的新增报404错误
28.视频132,单条删除,无法删除,查看前端代码有报错
29.报500错误,说utf-8啥的,
30.给管理员添角色,左侧未添加列表为空,然而,视频中的却不为空
31. 177集admin分配role,点击向右添加,保存后报错:
32.jsp文件明明定义了某个函数,但是页面显示不出来,查看console,报错说没有这个函数,这是因为浏览器有缓存的原因,按ctrl+f5强制刷新,然以后在重启服务器即可解决问题。
33.感觉debug自己还不会,这是一项必备的技能,后边有必要在B站上搜索下debug教程看看。
34.在pom中加入依赖,在web.xml中增加配置后,需要在右侧maven导航条刷新,在上方artifact那边添加library,类里边如果导包不成功,那么重启idea就好了
35. p247运行项目直接报错:
36.老师讲要会看异常,后台框架里的异常,一般是后一个异常导致了前一个异常,所以看异常要最先看最后一个causeby:往往最后这个能解决99%问题。还有1%是xml文件写错了。
37. 252集测试2,我的roleOperator无法显示内容
38. 285集yml文件读取,测试test遇到找不到类异常
以下为解决办法:
39 288集spring整合mybaitis报错
40.项目看到290集,需要用到Redis,所以暂停项目学习,转入Redis学习。
41.Idea如何同时运行多个项目:点击edit configuration,然后如下图,报错即可,只要端口号不重复,就可以运行多个项目。
42. 重要错误parent的版本号对不上报错:Cann
说明:/xxx/xxx/xxx/xxx/webapps修改的项目默认路径/xxx/xxx/xxx/wxs_home 修改的默认项目,放入自定义的首页index.jsp/index.html ;顺便放入错误提示页面error.jsp
错误提示页面:
error.jsp
<%@ page language="java" contentTy
1 web.xml
在Tomcat的conf文件夹下的web.xml文件中根元素下添加
以下内容,分别对应错误代码号和错误的网址,建议把错误网页放置在ROOT目录下。这样就直接可用’/'前缀指定该网页了。
<error-page>
<error-code>400</error-code>
<location>...
Seam - 语境相关的组件[满江红20071230]............................................................................................................................ 1
Java EE 框架..................................................................................................................................................................................1
Table of Contents........................................................................................................................................................................... 2
JBoss Seam 简介......................................................................................................................................................................... 11
Chapter 1. Seam 入门.................................................................................................................................................................14
1.1. 试试看.......................................................................................................................................................................... 14
1.1.1. 在JBoss AS 上运行示例..................................................................................................................................14
1.1.2. 在Tomcat 服务器上运行示例.......................................................................................................................... 15
1.1.3. 运行测试........................................................................................................................................................... 15
1.2. 第一个例子:注册示例.............................................................................................................................................. 15
1.2.1. 了解代码........................................................................................................................................................... 16
1.2.2. 工作原理........................................................................................................................................................... 26
1.3. Seam 中的可点击列表:消息示例............................................................................................................................. 27
1.3.1. 理解代码........................................................................................................................................................... 27
1.3.2. 工作原理........................................................................................................................................................... 32
1.4. Seam 和jBPM:待办事项列表(todo list)示例..................................................................................................... 32
1.4.1. 理解代码........................................................................................................................................................... 33
1.4.2. 工作原理........................................................................................................................................................... 39
1.5. Seam 页面流:猜数字范例........................................................................................................................................ 40
1.5.1. 理解代码........................................................................................................................................................... 40
1.5.2. 工作原理........................................................................................................................................................... 45
1.6. 一个完整的Seam 应用程序:宾馆预订范例............................................................................................................ 45
1.6.1. 介绍................................................................................................................................................................... 46
1.6.2. 预订系统概况................................................................................................................................................... 48
1.6.3. 理解Seam 业务对话(Conversation)................................................................................................................. 48
1.6.4. Seam 的UI 控制库........................................................................................................................................... 55
1.6.5. Seam 调试页面................................................................................................................................................. 56
1.7. 一个使用Seam 和jBPM 的完整范例:DVD 商店...................................................................................................57
1.8. 一个使用Seam 工作空间管理(workspace management)的完整范例:Issue Tracker........................................59
1.9. 结合Seam 和Hibernate 的范例:Hibernate 预订系统............................................................................................. 60
1.10. 一个RESTful 的Seam 应用程序:Blog 范例......................................................................................................... 60
1.10.1. 使用“拉”风格的MVC................................................................................................................................... 61
1.10.2. 可收藏的搜索结果页面................................................................................................................................. 63
1.10.3. 在RESTful 应用程序中使用“推”风格("push"-style)的MVC................................................................65
1.11. 在JBoss 中用JSF 1.2 RI 运行Seam 的范例............................................................................................................68
Chapter 2. 用Seam-gen 起步......................................................................................................................................................69
2.1. 准备活动...................................................................................................................................................................... 69
2.2. 建立一个新的Eclipse 项目........................................................................................................................................ 69
2.3. 创建新动作.................................................................................................................................................................. 72
2.4. 创建有动作的表单(form)...................................................................................................................................... 73
2.5. 从现有数据库生成应用程序...................................................................................................................................... 74
2.6. 将应用部署为EAR..................................................................................................................................................... 75
2.7. Seam 与增量热部署.................................................................................................................................................... 75
3 / 347
2.8. 在Jboss 4.0 下使用Seam............................................................................................................................................76
2.8.1. 安装JBoss 4.0...................................................................................................................................................76
2.8.2. 安装JSF 1.2 RI................................................................................................................................................. 76
Chapter 3. 上下文相关的组件模型............................................................................................................................................76
3.1. Seam 上下文.................................................................................................................................................................76
3.1.1. Stateless context(无状态上下文)................................................................................................................. 77
3.1.2. Event context(事件上下文)..........................................................................................................................77
3.1.3. Page context(页面上下文)............................................................................................................................77
3.1.4. Conversation context(业务会话上下文)......................................................................................................77
3.1.5. Session context(Session 上下文)..................................................................................................................78
3.1.6. Business process context (业务流程上下文)..............................................................................................78
3.1.7. Application context(应用上下文).................................................................................................................78
3.1.8. Context variables(上下文变量)....................................................................................................................79
3.1.9. Context 搜索优先级..........................................................................................................................................79
3.1.10. 并发模型......................................................................................................................................................... 79
3.2. Seam 组件....................................................................................................................................................................80
3.2.1. 无状态Session Bean......................................................................................................................................... 80
3.2.2. 有状态Session Bean......................................................................................................................................... 80
3.2.3. 实体Bean.......................................................................................................................................................... 81
3.2.4. JavaBeans.......................................................................................................................................................... 81
3.2.5. 消息驱动Bean.................................................................................................................................................. 82
3.2.6. 拦截................................................................................................................................................................... 82
3.2.7. 组件名字........................................................................................................................................................... 82
3.2.8. 定义组件范围(Defining the Component Scope)......................................................................................... 83
3.2.9. 具有多个角色的组件(Components with multiple roles)............................................................................ 84
3.2.10. 内置组件......................................................................................................................................................... 84
3.3. 双向注入...................................................................................................................................................................... 85
3.4. Lifecycle methods(生命周期方法)......................................................................................................................... 87
3.5. 条件装载(Conditional installation)........................................................................................................................ 87
3.6. 日志...............................................................................................................................................................................88
3.7. Mutable 接口和@ReadOnly........................................................................................................................................89
3.8. Factory 和Manager 组件.............................................................................................................................................91
Chapter 4. 配置Seam 组件.........................................................................................................................................................93
4.1. 通过属性设置来配置组件.......................................................................................................................................... 93
4.2. 通过components.xml 来配置组件.............................................................................................................................93
4.3. 细粒度的配置文件...................................................................................................................................................... 97
4.4. 可配置的属性类型...................................................................................................................................................... 97
4.5. 使用XML 命名空间................................................................................................................................................... 98
Chapter 5. 事件、拦截器和异常处理..................................................................................................................................... 101
5.1. Seam 事件...................................................................................................................................................................101
5.1.1. 页面动作......................................................................................................................................................... 102
5.1.2. 组件驱动的事件............................................................................................................................................. 108
5.1.3. 上下文事件..................................................................................................................................................... 109
5.2. Seam 拦截器..............................................................................................................................................................110
5.3. 管理异常.....................................................................................................................................................................112
5.3.1. 异常和事务..................................................................................................................................................... 112
5.3.2. 激活Seam 异常处理...................................................................................................................................... 113
4 / 347
5.3.3. 使用注解处理异常......................................................................................................................................... 113
5.3.4. 用XML 处理异常.......................................................................................................................................... 114
5.3.5. 一些常见的异常............................................................................................................................................. 115
Chapter 6. 对话以及工作区管理..............................................................................................................................................116
6.1. Seam 的对话模型.......................................................................................................................................................116
6.2. 嵌套对话.....................................................................................................................................................................118
6.3. 使用GET 请求来开始一个对话............................................................................................................................... 118
6.4. 利用<s:link>以及<s:button>......................................................................................................................................119
6.5. 成功信息.................................................................................................................................................................... 121
6.6. 使用“显式”的对话id.................................................................................................................................................121
6.7. 工作区管理................................................................................................................................................................ 122
6.7.1. 工作区管理及JSF 导航................................................................................................................................. 122
6.7.2. 工作区管理和jPDL 页面流........................................................................................................................... 122
6.7.3. 对话转换器..................................................................................................................................................... 123
6.7.4. 对话列表......................................................................................................................................................... 124
6.7.5. 导航控件......................................................................................................................................................... 125
6.8. 对话组件和JSF 组件绑定........................................................................................................................................ 125
6.9. 对话组件的并发调用................................................................................................................................................ 126
6.9.1. RichFaces Ajax................................................................................................................................................ 127
Chapter 7. 页面流和业务流程..................................................................................................................................................128
7.1. Seam 中的页面流...................................................................................................................................................... 128
7.1.1. 两种导航模型................................................................................................................................................. 128
7.1.2. Seam 和后退按钮........................................................................................................................................... 131
7.2. 使用jPDL 页面流......................................................................................................................................................132
7.2.1. 安装页面流..................................................................................................................................................... 132
7.2.2. 开始页面流..................................................................................................................................................... 133
7.2.3. 页面节点和跳转............................................................................................................................................. 134
7.2.4. 流程控制......................................................................................................................................................... 135
7.2.5. 流程的结束..................................................................................................................................................... 135
7.2.6. 页面流组合..................................................................................................................................................... 135
7.3. Seam 中的业务流程管理.......................................................................................................................................... 136
7.4. 使用jPDL 业务流程定义..........................................................................................................................................137
7.4.1. 安装流程定义................................................................................................................................................. 137
7.4.2. 初始化Actor id............................................................................................................................................... 137
7.4.3. 启动一个业务流程......................................................................................................................................... 138
7.4.4. 任务分配......................................................................................................................................................... 138
7.4.5. 任务列表......................................................................................................................................................... 138
7.4.6. 执行一个任务................................................................................................................................................. 139
Chapter 8. Seam 和对象/关系映射...........................................................................................................................................140
8.1. 简介.............................................................................................................................................................................140
8.2. Seam 管理的事务...................................................................................................................................................... 140
8.2.1. 关闭Seam 管理的事务.................................................................................................................................. 141
8.2.2. 配置Seam 事务管理器.................................................................................................................................. 142
8.2.3. 事务同步......................................................................................................................................................... 142
8.3. Seam 管理的持久化上下文...................................................................................................................................... 142
8.3.1. 在Seam 管理的持久化上下文中使用JPA....................................................................................................143
8.3.2. 使用Seam 管理的Hibernate 会话................................................................................................................. 143
5 / 347
8.3.3. Seam 管理的持久化上下文和原子会话........................................................................................................ 144
8.4. 使用JPA “代理(delegate)”...................................................................................................................................145
8.5. 在EJB-QL/HQL 中使用EL......................................................................................................................................146
8.6. 使用Hibernate 过滤器.............................................................................................................................................. 146
Chapter 9. Seam 中的JSF 表单验证........................................................................................................................................147
Chapter 10. Groovy 集成.......................................................................................................................................................... 152
10.1. Groovy 简介............................................................................................................................................................. 152
10.2. 用Groovy 编写Seam 应用..................................................................................................................................... 152
10.2.1. 编写Groovy 组件.........................................................................................................................................152
10.2.2. seam-gen........................................................................................................................................................ 154
10.3. 部署.......................................................................................................................................................................... 154
10.3.1. 部署Groovy 代码.........................................................................................................................................155
10.3.2. 开发时部署本地.groovy 文件.......................................................................................................................155
10.3.3. seam-gen........................................................................................................................................................ 155
Chapter 11. Seam 应用程序框架..............................................................................................................................................155
11.1. 简介...........................................................................................................................................................................156
11.2. Home 对象................................................................................................................................................................157
11.3. Query 对象................................................................................................................................................................161
11.4. Controller 对象......................................................................................................................................................... 163
Chapter 12. Seam 和JBoss 规则.............................................................................................................................................. 164
12.1. 安装规则.................................................................................................................................................................. 164
12.2. 在Seam 组件中使用规则....................................................................................................................................... 165
12.3. 在jBPM 流程定义中使用规则...............................................................................................................................166
Chapter 13. 安全........................................................................................................................................................................168
13.1. 概述.......................................................................................................................................................................... 168
13.1.1. 哪种模式更适合我的应用程序呢?............................................................................................................168
13.2. 需求.......................................................................................................................................................................... 168
13.3. 取消安全.................................................................................................................................................................. 168
13.4. 验证.......................................................................................................................................................................... 169
13.4.1. 配置............................................................................................................................................................... 169
13.4.2. 编写验证方法............................................................................................................................................... 169
13.4.3. 编写登录表单............................................................................................................................................... 171
13.4.4. 简化配置- 概述..........................................................................................................................................172
13.4.5. 处理安全异常............................................................................................................................................... 172
13.4.6. 登录重定向................................................................................................................................................... 172
13.4.7. HTTP 验证.................................................................................................................................................... 173
13.4.8. 高级验证特性............................................................................................................................................... 174
13.5. 错误消息.................................................................................................................................................................. 174
13.6. 授权.......................................................................................................................................................................... 175
13.6.1. 核心概念....................................................................................................................................................... 175
13.6.2. 保护组件....................................................................................................................................................... 175
13.6.3. 用户界面中的安全....................................................................................................................................... 177
13.6.4. 保护页面....................................................................................................................................................... 178
13.6.5. 保护实体....................................................................................................................................................... 178
13.7. 编写安全规则.......................................................................................................................................................... 180
13.7.1. 许可概述....................................................................................................................................................... 180
13.7.2. 配置规则文件............................................................................................................................................... 180
6 / 347
13.7.3. 创建安全规则文件....................................................................................................................................... 181
13.8. SSL 安全...................................................................................................................................................................183
13.9. 实现Captcha 测试................................................................................................................................................... 183
13.9.1. 配置Captcha Servlet.....................................................................................................................................184
13.9.2. 添加Captcha 到页面.................................................................................................................................... 184
13.9.3. 定制Captcha 图片........................................................................................................................................ 184
Chapter 14. 国际化和主题........................................................................................................................................................185
14.1. 本地化...................................................................................................................................................................... 185
14.2. 标签.......................................................................................................................................................................... 186
14.2.1. 定义标签....................................................................................................................................................... 186
14.2.2. 标签显示....................................................................................................................................................... 187
14.2.3. Faces Messages..............................................................................................................................................187
14.3. 时区.......................................................................................................................................................................... 188
14.4. 主题.......................................................................................................................................................................... 188
14.5. 使用cookie 保存locale 和主题设置.......................................................................................................................189
Chapter 15. Seam Text...............................................................................................................................................................190
15.1. 基本格式化.............................................................................................................................................................. 190
15.2. 输入代码和有特殊字符的文本............................................................................................................................... 192
15.3. 链接.......................................................................................................................................................................... 193
15.4. 输入HTML.............................................................................................................................................................. 193
Chapter 16. iText PDF 生成...................................................................................................................................................... 193
16.1. 使用PDF 支持......................................................................................................................................................... 193
16.1.1. 创建一个文档............................................................................................................................................... 194
16.1.2. 基本的文本元素........................................................................................................................................... 194
16.1.3. 页眉和页脚................................................................................................................................................... 197
16.1.4. 章节............................................................................................................................................................... 198
16.1.5. 列表............................................................................................................................................................... 199
16.1.6. 表格............................................................................................................................................................... 200
16.1.7. 文档常量....................................................................................................................................................... 202
16.1.8. iText 配置...................................................................................................................................................... 202
16.2. 图表.......................................................................................................................................................................... 203
16.3. 柱状图编码.............................................................................................................................................................. 207
16.4. 更详细的文档.......................................................................................................................................................... 208
Chapter 17. 电子邮件................................................................................................................................................................208
17.1. 创建一条消息.......................................................................................................................................................... 208
17.1.1. 附件............................................................................................................................................................... 209
17.1.2. HTML/Text 交替部分..................................................................................................................................210
17.1.3. 多个收件人................................................................................................................................................... 211
17.1.4. 多条信息....................................................................................................................................................... 211
17.1.5. 模板................................................................................................................................................................211
17.1.6. 国际化........................................................................................................................................................... 212
17.1.7. 其它的标识头............................................................................................................................................... 212
17.2. 接收邮件.................................................................................................................................................................. 213
17.3. 配置.......................................................................................................................................................................... 213
17.3.1. mailSession..................................................................................................................................................214
17.4. Meldware.................................................................................................................................................................. 214
17.5. 标签.......................................................................................................................................................................... 215
7 / 347
Chapter 18. 异步和消息............................................................................................................................................................217
18.1. 异步.......................................................................................................................................................................... 217
18.1.1. 异步方法....................................................................................................................................................... 218
18.1.2. 包含Quartz Dispatcher 的异步方法.............................................................................................................220
18.1.3. 异步事件....................................................................................................................................................... 223
18.2. Seam 中的消息........................................................................................................................................................ 223
18.2.1. 配置............................................................................................................................................................... 223
18.2.2. 发送消息....................................................................................................................................................... 223
18.2.3. 利用消息驱动Bean 接收消息......................................................................................................................224
18.2.4. 在客户端接收消息....................................................................................................................................... 224
Chapter 19. 缓存........................................................................................................................................................................225
19.1. 在Seam 中使用JBossCache...................................................................................................................................225
19.2. 页片段缓存.............................................................................................................................................................. 226
Chapter 20. Web Services.......................................................................................................................................................... 227
20.1. 配置和打包.............................................................................................................................................................. 227
20.2. 对话的Web Services................................................................................................................................................228
20.2.1. 建议策略....................................................................................................................................................... 229
20.3. Web Servic 范例....................................................................................................................................................... 229
Chapter 21. Remoting................................................................................................................................................................230
21.1. 配置.......................................................................................................................................................................... 231
21.2. Seam 对象.................................................................................................................................................................231
21.2.1. Hello World 示例.......................................................................................................................................... 231
21.2.2. Seam.Component...........................................................................................................................................233
21.2.3. Seam.Remoting..............................................................................................................................................235
21.3. EL 表达式求值........................................................................................................................................................ 235
21.4. 客户端接口.............................................................................................................................................................. 235
21.5. 上下文...................................................................................................................................................................... 236
21.5.1. 设置和读取对话ID......................................................................................................................................236
21.5.2. 当前对话范围内的远程调用........................................................................................................................ 236
21.6. 批量请求.................................................................................................................................................................. 237
21.7. 使用数据类型.......................................................................................................................................................... 237
21.7.1. Primitives / Basic 类型.................................................................................................................................237
21.7.2. JavaBeans...................................................................................................................................................... 237
21.7.3. Date 和Time................................................................................................................................................. 238
21.7.4. Enums 枚举类型.......................................................................................................................................... 238
21.7.5. Collections 集合........................................................................................................................................... 238
21.8. 调试.......................................................................................................................................................................... 239
21.9. 加载消息.................................................................................................................................................................. 239
21.9.1. 修改信息....................................................................................................................................................... 239
21.9.2. 隐藏加载信息............................................................................................................................................... 239
21.9.3. 自定义加载指示器....................................................................................................................................... 240
21.10. 控制返回数据........................................................................................................................................................ 240
21.10.1. 一般字段的约束......................................................................................................................................... 241
21.10.2. 集合和映射的约束..................................................................................................................................... 241
21.10.3. 特定类型对象的约束................................................................................................................................. 241
21.10.4. 组合约束..................................................................................................................................................... 241
21.11. JMS 消息................................................................................................................................................................ 242
8 / 347
21.11.1. 配置..............................................................................................................................................................242
21.11.2. 订阅JMS 主题............................................................................................................................................ 242
21.11.3. 退订主题..................................................................................................................................................... 242
21.11.4. 调整轮询过程............................................................................................................................................. 242
Chapter 22. Seam 和Google 的Web 工具包(GWT)................................................................................................................243
22.1. 配置.......................................................................................................................................................................... 243
22.2. 准备你的组件.......................................................................................................................................................... 243
22.3. 将GWT 小组件接到Seam 组件............................................................................................................................. 244
22.4. GWT Ant Targets...................................................................................................................................................... 246
Chapter 23. Spring Framework 集成........................................................................................................................................ 247
23.1. 把Seam 组件注入Spring Bean 中.......................................................................................................................... 248
23.2. 将Spring Bean 注入到Seam 组件中...................................................................................................................... 249
23.3. 将Spring Bean 转换为Seam 组件.......................................................................................................................... 250
23.4. Seam 作用域的Spring Bean................................................................................................................................... 250
23.5. 使用Spring PlatformTransactionManagement........................................................................................................251
23.6. 在Spring 中使用Seam 管理的持久化上下文....................................................................................................... 251
23.7. 在Spring 中使用Seam 管理的Hibernate 会话......................................................................................................253
23.8. 作为Seam 组件的Spring 应用上下文................................................................................................................... 253
23.9. 使用Spring TaskExecutor 的@Asynchronous.........................................................................................................253
Chapter 24. Hibernate Search.................................................................................................................................................... 254
24.1. 简介.......................................................................................................................................................................... 254
24.2. 配置.......................................................................................................................................................................... 254
Note............................................................................................................................................................................255
Note............................................................................................................................................................................255
24.3. 用法.......................................................................................................................................................................... 256
Note............................................................................................................................................................................256
Caution.......................................................................................................................................................................257
Chapter 25. Seam 配置和Seam 应用程序打包........................................................................................................................258
25.1. Seam 基本配置........................................................................................................................................................ 258
25.1.1. 将Seam 与JSF 和servlet 容器集成.......................................................................................................... 258
25.1.2. 使用Facelets................................................................................................................................................. 258
25.1.3. Seam Resource Servlet.................................................................................................................................. 259
25.1.4. Seam Servlet 过滤器.....................................................................................................................................259
25.1.5. 将Seam 与你的EJB 容器集成.................................................................................................................... 262
25.1.6. 切记!........................................................................................................................................................... 263
25.2. 在Java EE 5 中配置Seam...................................................................................................................................... 264
25.2.1. 打包............................................................................................................................................................... 264
25.3. 在J2EE 中配置Seam..............................................................................................................................................265
25.3.1. 在Seam 中引导Hibernate........................................................................................................................... 266
25.3.2. 在Seam 中引导JPA.....................................................................................................................................266
25.3.3. 打包............................................................................................................................................................... 266
25.4. 在Java SE 中配置Seam,没有内嵌JBoss............................................................................................................267
25.5. 用嵌入式的JBoss 在Java SE 中配置Seam...........................................................................................................267
25.5.1. 安装嵌入式的JBoss.....................................................................................................................................268
25.5.2. 打包............................................................................................................................................................... 268
25.6. 在Seam 中配置jBPM.............................................................................................................................................269
25.6.1. 打包............................................................................................................................................................... 270
9 / 347
25.7. 在Portal 中配置Seam.............................................................................................................................................271
25.8. 在JBoss AS 中配置SFSB 和会话超时...................................................................................................................271
Chapter 26. Seam on OC4J........................................................................................................................................................272
26.1. jee5/booking 实例................................................................................................................................................... 272
26.1.1. 预订酒店实例的依赖包............................................................................................................................... 273
26.1.2. OC4J 需要的额外依赖包..............................................................................................................................273
26.1.3. 配置文件的改变........................................................................................................................................... 273
26.1.4. 构建jee5/booking 实例............................................................................................................................... 274
26.2. 部署Seam 应用程序到OC4J 中............................................................................................................................. 274
26.3. 将一个使用seam-gen 创建的应用程序部署到OC4J 中。.............................................................................. 275
26.3.1. seam-gen 之类的应用程序的OC4J 部署描述符........................................................................................ 280
Chapter 27. Seam 注解..............................................................................................................................................................281
27.1. 用于定义组件的注解.............................................................................................................................................. 281
27.2. 用于双向注入的注解.............................................................................................................................................. 283
27.3. 关于组件生命周期方法的注解............................................................................................................................... 286
27.4. 用于声明上下文的注解.......................................................................................................................................... 286
27.5. 用于在J2EE 环境中使用Seam JavaBean 组件的注解......................................................................................... 289
27.6. 用于异常的注解...................................................................................................................................................... 289
27.7. 用于Seam Remoting 的注解................................................................................................................................. 290
27.8. 用于Seam 拦截器(interceptor)的注解...............................................................................................................290
27.9. 用于异步(asynchronicity)的注解....................................................................................................................... 291
27.10. 用于JSF 的注解.................................................................................................................................................... 291
27.10.1. 和dataTable 一起使用的注解...................................................................................................................292
27.11. 用于数据绑定的元数据注解................................................................................................................................ 292
27.12. 用于封包(packing)的注解.................................................................................................................................. 293
27.13. 用于和Servlet 容器集成的注解............................................................................................................................293
Chapter 28. 内置Seam 组件.....................................................................................................................................................294
28.1. 上下文注入组件...................................................................................................................................................... 294
28.2. 工具组件.................................................................................................................................................................. 294
28.3. 组件的国际化和主题.............................................................................................................................................. 296
28.4. 控制对话组件.......................................................................................................................................................... 297
28.5. 与jBPM 相关的组件...............................................................................................................................................298
28.6. 与安全相关的组件.................................................................................................................................................. 300
28.7. 与JMS 相关的组件.................................................................................................................................................300
28.8. 与邮件相关的组件.................................................................................................................................................. 300
28.9. 基础组件.................................................................................................................................................................. 301
28.10. 杂项组件................................................................................................................................................................ 303
28.11. 特殊组件.................................................................................................................................................................303
Chapter 29. Seam 的JSF 控件..................................................................................................................................................305
29.1. 标签.......................................................................................................................................................................... 305
29.2. 注解.......................................................................................................................................................................... 319
Chapter 30. 表达式语言增强....................................................................................................................................................320
30.1. 参数方法绑定.......................................................................................................................................................... 320
30.1.1. 用法............................................................................................................................................................... 320
30.1.2. 限制............................................................................................................................................................... 321
30.2. 参数值绑定.............................................................................................................................................................. 321
30.3. 映射.......................................................................................................................................................................... 322
10 / 347
Chapter 31. 测试Seam 应用程序.....................................................................................................
1、web系统开发过程中经常遇见400/404/500类型的错误页面,对于开发人员而言见到这种页面多了可能觉得问题不大,但是实际运用当中是面向客户的,需要配置一个合理的自定义错误页面。
2、本文只提Tomcat设置400/404/500自定义错误页面(推荐),Springmvc controller配置自定义错误页方式点击这里~
1、/WEB-INF/web.xml
在
tomcat中修改
tomcat安装根目录–>conf–>web.xml
配置文件就可以自定义
错误发生时的提示
界面,具体修改方法是在</web-app>上添加标签: <!--
错误页面处理 -->
<error-page>
<error-code>404</error-code>
<location>/error.jsp</location>
以前开发的时候,一直没错处理错误页面的问题,如果tomcat报错,就直接把错误的信息打印出来,找不到地址的时候就直接给出一个404错误,因为做的项目一直是没有上线的,所以,一直没有留意过这个问题,所以今天要记录一下错误的页面的指定。error-page元素就是用来克服这些问题的。//放置于web.xml末尾处
<error-page>
</error-page>它有两个可能的子元素,分别是:<err
你好!对于Tomcat 8启动界面出现乱码的问题,可以尝试以下几种解决方案:
1. 确保操作系统的默认编码与Tomcat配置文件的字符编码一致。可以通过编辑`conf/server.xml`文件,找到以下配置项:
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" URIEncoding="UTF-8"/>
确保`URIEncoding`的值为`UTF-8`。
2. 检查Tomcat的启动脚本(例如`catalina.sh`或`catalina.bat`)中的环境变量设置。确保`JAVA_OPTS`中没有设置错误的字符编码。
3. 检查系统环境变量中的`LANG`和`LC_ALL`变量是否正确设置。可以尝试将其设置为合适的值,例如:
export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8
4. 检查Tomcat所使用的JDK是否正确安装,并且JDK的默认字符编码与Tomcat配置文件一致。
5. 如果以上方法都无效,尝试在启动脚本中添加以下参数来指定编码:
-Dfile.encoding=UTF-8
请根据你的具体情况尝试以上方法,希望能解决你的问题。如果还有其他问题,请随时告诉我。