首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Spring项目的不正确构建

问Spring项目的不正确构建
EN

Stack Overflow用户
提问于 2016-11-07 11:18:00
回答 1查看 84关注 0票数 0

我有一个小型的MVC项目,可以由Tomcat或Git中的webapp运行程序在IDEA中构建。它工作得很完美,但当我构建我的项目时,它突然在localhost:8080中打开,并看到了js和css文件无法工作的问题。我在调试器(F12)中打开它,并注意到在所有文件中都有jsp页面的HTML代码。如果需要更多的信息,写在评论,我会发送它。

你可以在这张照片上看到:

​

以下是我的项目结构:

​

​

补充:

servlet-context.xml:

代码语言:javascript
复制
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:beans="http://www.springframework.org/schema/beans"
             xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
             xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd">

    <!-- DispatcherServlet Context: defines this servlet's request-processing 
        infrastructure -->

    <!-- Enables the Spring MVC @Controller programming model -->
    <annotation-driven />

    <!-- Handles HTTP GET requests for /resources/** by efficiently serving
        up static resources in the ${webappRoot}/resources directory -->
    <resources mapping="/resources/**" location="/resources/" />
    <resources mapping="/resources/**" location="/resources/" />

    <context:component-scan base-package="com.ya.pokupay" />

    <!-- Resolves views selected for rendering by @Controllers to .jsp resources
        in the /WEB-INF/views directory -->
    <beans:bean
            class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <beans:property name="prefix" value="/WEB-INF/views/" />
        <beans:property name="suffix" value=".jsp" />
    </beans:bean>

    <!--&lt;!&ndash;Local database&ndash;&gt;-->
    <!--<beans:bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"-->
                <!--destroy-method="close">-->
        <!--<beans:property name="driverClassName" value="com.mysql.jdbc.Driver" />-->
        <!--<beans:property name="url" value="jdbc:mysql://localhost:3306/shopDB" />-->
        <!--<beans:property name="username" value="*****" />-->
        <!--<beans:property name="password" value="*****" />-->
    <!--</beans:bean>-->

    <!--Remote database-->
    <beans:bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
                destroy-method="close">
        <beans:property name="driverClassName" value="com.mysql.jdbc.Driver" />
        <beans:property name="url" value="jdbc:mysql://db4free.net:3306/yapokupay" />
        <beans:property name="username" value="******" />
        <beans:property name="password" value="******" />
    </beans:bean>

    <!-- Hibernate 4 SessionFactory Bean definition -->
    <beans:bean id="hibernate4AnnotatedSessionFactory"
                class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
        <beans:property name="dataSource" ref="dataSource" />
        <beans:property name="annotatedClasses">
            <beans:list>
                <beans:value>com.ya.pokupay.model.Advert</beans:value>
            </beans:list>
        </beans:property>
        <beans:property name="hibernateProperties">
            <beans:props>
                <beans:prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect
                </beans:prop>
                <beans:prop key="hibernate.show_sql">true</beans:prop>
            </beans:props>
        </beans:property>
    </beans:bean>

    <beans:bean id="advertDAO" class="com.ya.pokupay.dao.AdvertDAOImpl">
        <beans:property name="sessionFactory" ref="hibernate4AnnotatedSessionFactory" />
    </beans:bean>
    <beans:bean id="advertService" class="com.ya.pokupay.service.AdvertServiceImpl">
        <beans:property name="advertDAO" ref="advertDAO"/>
    </beans:bean>
    <context:component-scan base-package="com.ya.pokupay" />

    <tx:annotation-driven transaction-manager="transactionManager"/>

    <beans:bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
        <beans:property name="sessionFactory" ref="hibernate4AnnotatedSessionFactory" />
    </beans:bean>


</beans:beans>

script.js:

代码语言:javascript
复制
$( document ).ready(function() {

    $(".dropdown-menu a").on("click", function () {
        var url = $(this).attr("href");
        if (url == '#') {
            history.replaceState('', '', '/');
        } else {
            history.pushState('', '', url);
        }

    })

});
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-11-08 09:33:26

非常感谢@Lucky的帮助。我想我找到了解决问题的办法。我在Controller @RequestMapping("/* *")中编写,这样您就可以在url中编写任何东西,并获得相同的jsp文件。当应用程序试图通过路径资源/**获取js和css文件时,它得到了相同的jsp页面。我刚刚删掉了**,它起作用了。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40463887

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档