Spring,将JavaScript(angular)添加到jps页面。不工作

时间:2017-06-29 12:21:26

标签: javascript angularjs spring spring-mvc

请任何帮助

使用 Spring 4.3.8.RELEASE

JPS页面,MyPage.jps

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>

<html>
<head>
    <title>MyPage</title>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
    <link rel="stylesheet" href="<c:url value="/WEB-INF/static/css/itemstyle.css"/>">



    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.4/angular.js"></script>

    <spring:url value="/static/js/app.js" var="a"/>
    <script src="${a}" type="text/javascript"  ></script>
    <script src="<spring:url value="/static/js/service/item_service.js" />"  type="text/javascript"  ></script>
    <script src="<spring:url value='/static/js/controller/item_controller.js' />"  type="text/javascript"  ></script>


</head>

<body ng-app="myApp">

<div class="generic-container" ng-controller="ItemController as ctrl">
    <div class="panel panel-default">
        <div class="panel-heading"><span class="lead">User Registration Form </span></div>
        <div class="formcontainer">
            <!-- form submit -->
        </div>
    </div>
    <div class="panel panel-default">
        <!-- Default panel contents -->
        <div class="panel-heading"><span class="lead">List of Users </span></div>
        <div class="tablecontainer">
            <table class="table table-hover">
                <thead>
                <tr>
                    <th>ID.</th>
                    <th>Name</th>
                    <th>Address</th>
                    <th>Email</th>
                    <th width="20%"></th>
                </tr>
                </thead>
                <tbody>
                <tr ng-repeat="i in ctrl.items">
                    <td><span ng-bind="i.id"></span></td>
                    <td><span ng-bind="i.name"></span></td>
                    <td><span ng-bind="i.price"></span></td>
                    <!--td>
                        <button type="button" ng-click="ctrl.edit(i.id)" class="btn btn-success custom-width">Edit</button>  <button type="button" ng-click="ctrl.remove(i.id)" class="btn btn-danger custom-width">Remove</button>
                    </td-->
                </tr>
                </tbody>
            </table>
        </div>
    </div>
</div>





</body>
</html>

Servlet item-serlvet

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">

    <context:component-scan base-package="mayan.example" />

    <context:annotation-config/>

    <mvc:resources mapping="/static/**" location="/WEB-INF/static/" cache-period="31556926"/>

    <mvc:annotation-driven/>
    <mvc:default-servlet-handler/>


    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/views/" />
        <property name="suffix" value=".jsp" />
    </bean>



</beans>

网络

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
         version="3.1">

    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <servlet-mapping>
        <servlet-name>item</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

    <servlet>
        <servlet-name>item</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>WEB-INF/app-context.xml</param-value>
    </context-param>

    <welcome-file-list>
        <welcome-file></welcome-file>
    </welcome-file-list>


</web-app>

我希望我不会重复,因为我已经读过:

JavaScript with Spring MVC doesn't work

Where do CSS and JavaScript files go in a Maven web app project?

https://www.mkyong.com/spring-mvc/spring-mvc-how-to-include-js-or-css-files-in-a-jsp-page/

Including css and js file in spring mvc 3

how to load js file in spring mvc

How to include js and CSS in JSP with spring MVC

以及更多

问题

java Scripts文件未加载。打算在网络资源中看到jps页面,如此

enter image description here

当文件app.js是这样的时候:

'use strict';

var App = angular.module('myApp',[]);

真的不知道该做什么,已经尝试了这么多,4个小时就解决了这个问题。求你帮忙!

我的项目:

enter image description here

0 个答案:

没有答案