2013-01-22 35 views
1

我想訪問託管在Tomcat 6服務器上的Web服務。當我在瀏覽器中輸入wsdl url時,系統會提示輸入憑據。如何解決Tomcat請求的令人討厭的授權彈出?

我得到一個彈出窗口來輸入用戶名和密碼。

A user name and password are being requested by http://localhost:8080. The site says: MyApplicationName 

我給了我的應用程序登錄細節。但它一次又一次地促使我。當我點擊取消時,我得到401未經授權的例外。

的tomcat-users.xml中

<?xml version='1.0' encoding='utf-8'?> 
<tomcat-users> 
    <user name="admin" password="" roles="manager"/> 
</tomcat-users> 

server.xml中有一些細節如下

<Server port="8205" shutdown="SHUTDOWN" debug="2"> 

    <!--APR library loader. Documentation at /docs/apr.html --> 
    <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" /> 
    <!--Initialize Jasper prior to webapps are loaded. Documentation at /docs/jasper-howto.html --> 
    <Listener className="org.apache.catalina.core.JasperListener" /> 
    <!-- JMX Support for the Tomcat server. Documentation at /docs/non-existent.html --> 
    <Listener className="org.apache.catalina.mbeans.ServerLifecycleListener" /> 
    <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" /> 

    <Service name="Catalina" debug="2"> 

    <Connector port="8080" protocol="HTTP/1.1" 
       connectionTimeout="20000" 
       redirectPort="8443" 
       scheme="http" 
       secure="false" 
       SSLEnabled="false" 
       debug="2" 
       emptySessionPath="true" 
       URIEncoding="UTF-8" /> 

    <!-- Define an AJP 1.3 Connector on port 8009 --> 
    <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" /> 

    <Engine name="Catalina" defaultHost="localhost" 
     debug="2"> 

     <Realm className="org.apache.catalina.realm.MemoryRealm"/> 

     <!-- Define the default virtual host 
      Note: XML Schema validation will not work with Xerces 2.2. 
     --> 
     <Host name="localhost" appBase="webapps" 
      unpackWARs="true" autoDeploy="true" 
      xmlValidation="false" xmlNamespaceAware="false" 
      debug="2"> 

      <Context path="" docBase="C:\mypath\app.war" debug="2"></Context>   

     <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" 
       prefix="localhost_access_log." suffix=".txt" pattern="common" resolveHosts="false"/> 

     </Host> 
    </Engine> 
    </Service> 
</Server> 

的web.xml

<?xml version="1.0" encoding="ISO-8859-1"?> 
<web-app xmlns="http://java.sun.com/xml/ns/javaee" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 
    version="2.5"> 


    <servlet> 
     <servlet-name>default</servlet-name> 
     <servlet-class>org.apache.catalina.servlets.DefaultServlet</servlet-class> 
     <init-param> 
      <param-name>debug</param-name> 
      <param-value>0</param-value> 
     </init-param> 
     <init-param> 
      <param-name>listings</param-name> 
      <param-value>false</param-value> 
     </init-param> 
     <load-on-startup>1</load-on-startup> 
    </servlet> 


    <servlet> 
     <servlet-name>jsp</servlet-name> 
     <servlet-class>org.apache.jasper.servlet.JspServlet</servlet-class> 
     <init-param> 
      <param-name>fork</param-name> 
      <param-value>false</param-value> 
     </init-param> 
     <init-param> 
      <param-name>xpoweredBy</param-name> 
      <param-value>false</param-value> 
     </init-param> 
     <load-on-startup>3</load-on-startup> 
    </servlet> 

</web-app> 

有人可以告訴我如何刪除這個彈出窗口,或者我需要輸入什麼用戶名和密碼。它會是我的應用程序特定的還是tomcat特定的?

+0

請提供web.xml文件的內容。該配置在 – MaVRoSCy

+0

@ MaVRoSCy上完成。感謝您的建議。我更新了我的問題。 – Patan

+0

查看此問題的接受答案: http://stackoverflow.com/questions/7726014/how-do-i-provide-basic-http-authentication-for-static-tomcat-webapps-without-cha – adranale

回答

0

嘗試把下面的服務標籤上面的最後一個偵聽標籤如下:

<GlobalNamingResources> 
<Resource name="UserDatabase" auth="Container" 
      type="org.apache.catalina.UserDatabase" 
      description="User database that can be updated and saved" 
      factory="org.apache.catalina.users.MemoryUserDatabaseFactory" 
      pathname="conf/tomcat-users.xml" /> 
</GlobalNamingResources> 

而且在當時的下

<Engine name="Catalina" defaultHost="localhost" 
    debug="2"> 

地址:

<Realm className="org.apache.catalina.realm.UserDatabaseRealm" 
     resourceName="UserDatabase"/> 

確保您更改UserDatabase資源中的路徑名設置爲tomcat-users.xml文件的正確路徑。您需要重新啓動tomcat才能使更改生效。

3

我也遇到了同樣的問題。 經過幾個小時的故障排除並嘗試所有可能的解決方案中提到的這個線程和其他類似的線程,我無法解決這個問題。 然後我可以確定我突然開始面對這個問題,因爲我最近在我的機器上安裝了Oracle,它使用了相同的端口8080. 我更改了我的server.xml文件中的端口號,現在它工作正常..

下面是變化的片段:

<Connector port="8081" protocol="HTTP/1.1" 
       connectionTimeout="20000" 
       redirectPort="8443" /> 
相關問題