当项目部署在tomcat上时,Mysql数据源无法正常工作

时间:2018-05-22 05:10:23

标签: java mysql tomcat deployment

部署在另一个系统中的Web应用程序JSF页面没有显示。虽然它在其他系统中工作正常。我在jsf页面中使用了primefaces。

下面的jsf页面在ADD New Data下面有数据表,在提交添加数据时会出现ADD New Data对话框,但它没有显示。

当我从eclipse运行时它工作正常

getting blank page with only button

的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" xmlns:web="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_3_0.xsd" id="WebApp_ID" version="3.0">
  <display-name>STCMedicalSystem</display-name>
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
  <resource-ref>
    <description>My DataSource Reference</description>
    <res-ref-name>jdbc/stc_medical</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
  </resource-ref>
<servlet>
        <servlet-name>FacesServlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>FacesServlet</servlet-name>
        <url-pattern>*.jsf</url-pattern>
    </servlet-mapping>
    <context-param>
        <description>State saving method: 'client' or 'server' (=default). See JSF Specification 2.5.2</description>
        <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
        <param-value>client</param-value>
    </context-param>
    <context-param>
        <param-name>javax.faces.CONFIG_FILES</param-name>
        <param-value>/WEB-INF/faces-config.xml</param-value>
    </context-param>
    <listener>
        <listener-class>com.sun.faces.config.ConfigureListener</listener-class>
    </listener>
    <context-param>
        <param-name>primefaces.THEME</param-name>
        <param-value>start</param-value>
    </context-param>
</web-app>

page.xhtml:

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:p="http://primefaces.prime.com.tr/ui">
<h:head>
    <title>STC Medical system</title>
    <link rel="shortcut icon" type="image/x-icon"
        href="../resources/images/favicon.ico" />
    <link href="../resources/css/style1.css" rel="stylesheet"
        type="text/css" />
    <link rel="stylesheet" type="text/css"
        href="../resources/css/sdmenu.css" />
    <script type="text/javascript" src="../resources/js/sdmenu.js"></script>
<h:body>
<h:form id="dbform">
                                                            <p:growl id="growl" />
                                                            <h:panelGrid>
                                                                <p:outputPanel>
                                                                    <h:outputText value="Filter by Flag(E, R, S, D, N): " />
                                                                    <h:selectOneMenu immediate="true"
                                                                        value="#{allMedVocAction.selectedFlag}"
                                                                        onchange="submit()"
                                                                        valueChangeListener="#{allMedVocAction.flagFilter}"
                                                                        render="true">
                                                                        <f:selectItem itemLabel="Select One" itemValue="all" />
                                                                        <f:selectItems id="options"
                                                                            value="#{allMedVocAction.flagNames}" />
                                                                    </h:selectOneMenu>
                                                                </p:outputPanel>
                                                            </h:panelGrid>
                                                            <h:panelGroup id="dbpanelgrid">
                                                                <p:dataTable style="width:800px;" id="tbl" var="med"
                                                                    value="#{allMedVocAction.searchResults}"
                                                                    paginator="true"
                                                                    paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
                                                                    rowsPerPageTemplate="5,10,15" rowKey="med.file"
                                                                    selection="med.selectedMedNo"
                                                                    columnClasses="text,number,number,number,text,text"
                                                                    rowClasses="table-evenRow,table-oddRow"
                                                                    update="excelPdfPanelGroup" rows="5"
                                                                    selectionMode="single"
                                                                    rowSelectListener="#{allMedVocAction.onDataSelect}">
    <p:column sortBy="#{med.brno}" filterBy="#{med.brno}"
                                                                        filterMatchMode="contains">
                                                                        <f:facet name="header">
                                                                            <h:outputText value="BRNO" />
                                                                        </f:facet>
                                                                        <h:outputText value="#{med.brno}" />
                                                                    </p:column>
<p:column style="text-align:center;">
                                                                        <f:facet name="header">
                                                                            <h:outputText value="EDIT" />
                                                                        </f:facet>
                                                                        <p:commandButton title="EDIT" onclick="dlg2.show();"
                                                                            render="tbl"
                                                                            action="#{allMedVocAction.editMcodeDetails}"
                                                                            image="ui-icon ui-icon-pencil"
                                                                            update="editfrom:editdevice,display" immediate="true">
                                                                            <f:setPropertyActionListener value="#{med}"
                                                                                target="#{allMedVocAction.selectedMedNo}" />
                                                                        </p:commandButton>
                                                                    </p:column>
                                                                </p:dataTable>
                                                                <!-- Delete Dialog box -->
                                                                <!-- Preview Dialog box -->
                                                            </h:panelGroup>
                                                        </h:form>
</h:body>
</html>

在tomcat服务器中部署之后,在tomcat访问日志中获取jsf页面的响应代码500。 context.xml中:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xml>
<Context path="/stc_medical">
<Resource name="jdbc/stc_medical" 
              auth="Container"
              type="javax.sql.DataSource" 
              username="root" 
              password="root"
              driverClassName="com.mysql.jdbc.Driver"
              url="jdbc:mysql://localhost:3306/stc_medical?autoReconnect=true"
              validationQuery="select 1"
              maxActive="10" 
              maxIdle="4"/>
</Context>

ConnectionPool类:

public class ConnectionPool {
    private static ConnectionPool pool = null;
    private static DataSource dataSource = null;

    private ConnectionPool() {
        try {
            InitialContext ic = new InitialContext();
            dataSource = (DataSource) ic
                    .lookup("java:/comp/env/jdbc/stc_medical");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

我在部署war文件时将mysql-connector-java-5.1.23-bin放在tomcat lib目录中,但无法访问数据库。 我尝试了很多方法,但无法找到解决方案。

0 个答案:

没有答案