java - 外部 jquery 文件在 spring MVC 中不起作用?

标签 java javascript spring jsp spring-mvc

我的 Jsp 是,

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%-- <%@include file="include.jsp"%> --%>

<%@ taglib prefix="form" uri="../tld/spring-form.tld" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
    <script type="text/javascript" src="/jquery/jquery-1.9.1.js"></script>
    <script type="text/javascript" src="/jquery/hello.js"></script>

</head>
<body>
<%out.println("Hello") ;%>
 <form:form  commandName="person">
        Select A or B :
        <form:input path="option" id="option" />
        <input type="button" value="Ajax Submit" onclick="hello();">

        <p id = "result"></p>

</form:form> 
</body>
</html>

out.println("Hello") 在浏览器中打印,并且也显示表单。只有外部 Jquery 无法进行 javaScript 调用。

我的调度程序 Servlet 将是,

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

我的外部 hello.js 包含 ,

function hello(){
    alert("Hello 99");
    var val = $("#option").val();
    alert("Option : "+val);
}

我的项目结构是,

enter image description here

当我单击按钮时,我会在控制台中看到此内容

Apr 8, 2013 9:03:08 PM org.springframework.web.servlet.DispatcherServlet noHandlerFound
WARNING: No mapping found for HTTP request with URI [/SampleChat/jquery/hello.js] in DispatcherServlet with name 'dispatcher'
Apr 8, 2013 9:03:09 PM org.springframework.web.servlet.DispatcherServlet noHandlerFound
WARNING: No mapping found for HTTP request with URI [/SampleChat/jquery/jquery-1.9.1.js] in DispatcherServlet with name 'dispatcher'

我需要调用 JavaScript 函数来获取警报。

好的答案绝对值得赞赏。

最佳答案

js文件中的ma​​deAjaxCall()在哪里?

我认为你正在尝试这样做

<input type="button" value="Ajax Submit" onclick="hello();">

你的代码看起来不错。

关于java - 外部 jquery 文件在 spring MVC 中不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15883103/

相关文章:

javascript - 图像结果未显示在页面上

java - Spring JPA插入连接表实体时不允许NULL

java - 没有类型为“org.springframework.data.jpa.repository.support.JpaEntityInformation”的合格 bean

java - 如何获取rgb中的颜色并将其放入MySQL数据库JColorChooser

Java 字符串缓冲区

java - 为什么对父构造函数的调用不是编译器为内部类生成的构造函数中的第一个调用?

javascript - "dom-to-image"图片跨域

java - 使用 Intent 将数据结果返回给父 Activity

javascript - 从 Angular 对象数组中获取特定对象

java - 使用 spring data jpa 在启动时将数据保存到数据库