【发布时间】:2013-04-08 15:28:13
【问题描述】:
我的 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 调用。
我的 dispatcher-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);
}
我的项目结构是,
当我点击按钮时,我会在控制台中看到这个
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 函数来获取警报。
肯定会感谢好的答案。
【问题讨论】:
-
我在你的 jsp 中看不到任何
<script>元素。您需要通过在<script>元素中引用它们来包含 javascript 脚本。 -
您可能必须像这样删除 src 中的斜杠
-
我添加了外部脚本。见
<script type="text/javascript" src="/jquery/jquery-1.9.1.js"></script>和<script type="text/javascript" src="/jquery/hello.js"></script> -
去掉了斜线还是不行。
-
什么不起作用?你遇到了什么错误?
标签: java javascript spring jsp spring-mvc