JWorld@TW the best professional Java site in Taiwan
      註冊 | 登入 | 全文檢索 | 排行榜  

» JWorld@TW » Servlet/JSP 討論區  

按列印兼容模式列印這個話題 列印話題    把這個話題寄給朋友 寄給朋友   
reply to postflat modego to previous topicgo to next topic
本主題所含的標籤
無標籤
作者 web.xml設定問題
weberhwang





發文: 45
積分: 0
於 2019-01-15 22:58 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
大家好

環境:
Windows 10 pro 繁體中文版
Tomcat 8.5.37
Servlet 3.1

請問
我想在web.xml中設定,當user亂輸入網址時,自動轉至index.jsp(首頁)
例如:我自己的網址是 http://localhost:8081/myWebSite/index.jsp
但有人輸入 http://localhost:8081/myWebSite/xxxx123123.jsp 時,將它導引至index.jsp頁面
所以我就加了最下面紅色那段(63-70行 顏色有點跑掉), 我的想法是「當前面所有的url patten都mapping不到時,最後就引導至index.jsp」

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns="http://xmlns.jcp.org/xml/ns/javaee"
  xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
  id="WebApp_ID" version="3.1">
  <display-name>myWebSite</display-name>
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
 
  <resource-ref>
    <description>DB Connection</description>
    <res-ref-name>jdbc/myoracle</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
  </resource-ref>
 
  <servlet>
    <servlet-name>HelloWorld</servlet-name>
    <servlet-class>servlet.HelloWorld</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>HelloWorld</servlet-name>
    <url-pattern>/HelloWorld</url-pattern>
  </servlet-mapping>
  <servlet>
    <servlet-name>HelloGet</servlet-name>
    <servlet-class>servlet.HelloGet</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>HelloGet</servlet-name>
    <url-pattern>/HelloGet</url-pattern>
  </servlet-mapping>
  <servlet>
    <servlet-name>HelloPost</servlet-name>
    <servlet-class>servlet.HelloPost</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>HelloPost</servlet-name>
    <url-pattern>/HelloPost</url-pattern>
  </servlet-mapping>
 
  <servlet>
    <servlet-name>MyCounter</servlet-name>
    <servlet-class>test.MyCounter</servlet-class>
    <init-param>
      <param-name>test</param-name>
      <param-value>test_value</param-value>
    </init-param>
    <init-param>
      <param-name>test1</param-name>
      <param-value>test1_value</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>
 
  <servlet-mapping>
    <servlet-name>MyCounter</servlet-name>
    <url-pattern>/MyCounter</url-pattern>
  </servlet-mapping>
 

    <servlet>
        <servlet-name>IndexJSP</servlet-name>
        <jsp-file>index.jsp</jsp-file>
    </servlet>
    <servlet-mapping>
        <servlet-name>IndexJSP</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>

</web-app>


但我發現,只要我一設定後,啟動Server就會出錯,無法啟動Server(若把該段設定拿掉又可以正常啟動Server),
錯誤訊息,如下
不知是那邊用法上出了問題? 各位先進指點 感謝。

一月 15, 2019 10:34:21 下午 org.apache.catalina.deploy.NamingResourcesImpl cleanUp
警告: Failed to retrieve JNDI naming context for container [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/myWebSite]] so no cleanup was performed for that container
javax.naming.NamingException: No naming context bound to this class loader
  at org.apache.naming.ContextBindings.getClassLoader(ContextBindings.java:268)
  at org.apache.catalina.deploy.NamingResourcesImpl.cleanUp(NamingResourcesImpl.java:1019)
  at org.apache.catalina.deploy.NamingResourcesImpl.stopInternal(NamingResourcesImpl.java:1002)
  at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:226)
  at org.apache.catalina.core.StandardContext.stopInternal(StandardContext.java:5514)
  at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:226)
  at org.apache.catalina.util.LifecycleBase.destroy(LifecycleBase.java:264)
  at org.apache.catalina.core.ContainerBase.removeChild(ContainerBase.java:856)
  at org.apache.catalina.core.ContainerBase.destroyInternal(ContainerBase.java:1042)
  at org.apache.catalina.util.LifecycleBase.destroy(LifecycleBase.java:297)
  at org.apache.catalina.core.ContainerBase.removeChild(ContainerBase.java:856)
  at org.apache.catalina.core.ContainerBase.destroyInternal(ContainerBase.java:1042)
  at org.apache.catalina.util.LifecycleBase.destroy(LifecycleBase.java:297)
  at org.apache.catalina.core.StandardService.destroyInternal(StandardService.java:588)
  at org.apache.catalina.util.LifecycleBase.destroy(LifecycleBase.java:297)
  at org.apache.catalina.core.StandardServer.destroyInternal(StandardServer.java:883)
  at org.apache.catalina.util.LifecycleBase.destroy(LifecycleBase.java:297)
  at org.apache.catalina.startup.Catalina.start(Catalina.java:691)
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
  at java.lang.reflect.Method.invoke(Unknown Source)
  at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:353)
  at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:493)

補充:我自己有另外試了下面這個方法是可行的,只是不知前述方法為何不行
<error-page>
  <error-code>404</error-code>
  <location>/index.jsp</location>
</error-page>

最後想請問...像我用 Tomcat 8.5.37 + Servlet 3.1 的話,關於web.xml的官方文件,
要去那邊找,我自己找了半天,大多是網友提供的片段教學,
不知有詳細的官方文件網址嗎?


weberhwang edited on 2019-01-17 14:24
reply to postreply to post
話題樹型展開
人氣 標題 作者 字數 發文時間
443 web.xml設定問題 weberhwang 5121 2019-01-15 22:58
337 Re:web.xml設定問題 kentyeh 505 2019-01-16 17:00
337 Re:web.xml設定問題 weberhwang 715 2019-01-16 19:21
301 Re:web.xml設定問題 kentyeh 341 2019-01-17 10:14
310 Re:web.xml設定問題 weberhwang 1480 2019-01-17 13:27
312 Re:web.xml設定問題 kentyeh 170 2019-01-17 15:55
» JWorld@TW »  Servlet/JSP 討論區

reply to postflat modego to previous topicgo to next topic
  已讀文章
  新的文章
  被刪除的文章
Jump to the top of page

JWorld@TW 本站商標資訊

Powered by Powerful JuteForum® Version Jute 1.5.8