Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/389.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Web服务(axis2)如何从Web.xml获取参数_Java_Xml_Web Services_Servlets_Axis2 - Fatal编程技术网

Java Web服务(axis2)如何从Web.xml获取参数

Java Web服务(axis2)如何从Web.xml获取参数,java,xml,web-services,servlets,axis2,Java,Xml,Web Services,Servlets,Axis2,我创建了一个简单的类,然后在EclipseLuna中使用Axis2创建了一个web服务,我需要为获得数据库连接的组件设置一些基本参数(主机、数据库名称、端口、用户、密码),我尝试从web.xml获取参数,但我无法获取 public class SearchPay { /*** * Search the payment * @param paramKey * @return return true or false */ public Str

我创建了一个简单的类,然后在EclipseLuna中使用Axis2创建了一个web服务,我需要为获得数据库连接的组件设置一些基本参数(主机、数据库名称、端口、用户、密码),我尝试从web.xml获取参数,但我无法获取

public class SearchPay {
    /***
     * Search the payment
     * @param paramKey
     * @return return true or false
     */
    public String PaySearch(String paramKey){

        ResultSet rsPayment=null;
        String xmlResp="";

        try{
            rsPayment = getData(paramKey);

            if(getRowCount(rsPayment )>0){
                while(rsPayment.next()){
                    if(rsPayment.getString("STATUS")!=null)
                        xmlResp = rsPayment.getString("STATUS").trim();

                    System.out.println(xmlResp);
                }
            }
        }catch(Exception e2){
            e2.printStackTrace();
        }finally{
            try{
                if(!rsPayment.isClosed()){
                    rsPayment.close();
                }
            }catch(Exception e1){
                e1.printStack();
            }
        }

        return xmlResp;
    }
}
我只有在使用Servlet类时才能这样做。但我不能使用前面的方法,因为Servlet使用doPost和doGet方法

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        ServletContext context = null;

        try{
            context = this.getServletContext();
            setBDHost(context.getInitParameter("bdhost"));
            setBDUser(context.getInitParameter("bduser"));
            setBDPassword(context.getInitParameter("bdpassword"));
            setBDPort(context.getInitParameter("bdport"));

        }catch(Exception ex){
            ex.printStackTrace();
        }

    }
这是web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>FirstWebServiceExample</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
    <welcome-file>/axis2-web/index.jsp</welcome-file>
  </welcome-file-list>
  <servlet>
    <display-name>Apache-Axis Servlet</display-name>
    <servlet-name>AxisServlet</servlet-name>
    <servlet-class>org.apache.axis2.transport.http.AxisServlet</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>AxisServlet</servlet-name>
    <url-pattern>/servlet/AxisServlet</url-pattern>
  </servlet-mapping>
  <servlet-mapping>
    <servlet-name>AxisServlet</servlet-name>
    <url-pattern>*.jws</url-pattern>
  </servlet-mapping>
  <servlet-mapping>
    <servlet-name>AxisServlet</servlet-name>
    <url-pattern>/services/*</url-pattern>
  </servlet-mapping>
  <servlet>
    <display-name>Apache-Axis Admin Servlet Web Admin</display-name>
    <servlet-name>AxisAdminServlet</servlet-name>
    <servlet-class>org.apache.axis2.transport.http.AxisAdminServlet</servlet-class>
    <load-on-startup>100</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>AxisAdminServlet</servlet-name>
    <url-pattern>/axis2-admin/*</url-pattern>
  </servlet-mapping>
  <context-param>
    <param-name>DBHost</param-name>
    <param-value>myHost</param-value>
  </context-param>
  <context-param>
    <param-name>DBUser</param-name>
    <param-value>myUser</param-value>
  </context-param>
  <context-param>
    <param-name>DBPassword</param-name>
    <param-value>myPassword</param-value>
  </context-param>
  <context-param>
    <param-name>DBPort</param-name>
    <param-value>myPort</param-value>
  </context-param>
</web-app>

FirstWebService示例
index.html
index.htm
index.jsp
default.html
default.htm
default.jsp
/axis2 web/index.jsp
ApacheAxisServlet
AxisServlet
org.apache.axis2.transport.http.AxisServlet
AxisServlet
/servlet/AxisServlet
AxisServlet
*jws先生
AxisServlet
/服务/*
Apache Axis管理Servlet Web管理
AxisAdminServlet
org.apache.axis2.transport.http.AxisAdminServlet
100
AxisAdminServlet
/axis2管理员/*
数据库主机
我的主人
数据库用户
我的用户
数据库密码
我的密码
数据端口
我的港口
您建议我如何从一些存档xml中获取参数


如果我使用Servlet类,我如何调用我的方法SearchPay(String)?如果该类使用doPost和doGet方法?

这可能会对您有所帮助吗?是否有必要在web.xml中配置这些参数?简单的属性文件不是一个选项吗?谢谢你的回答Michal!不,我可以在任何地方配置,但我遇到了同样的问题!文件的路径(web.xml或属性文件)是我找不到的。您需要从类路径读取文件,即不使用文件IO。看看你可能也会考虑阅读