Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用SpringMVC访问外部javascript文件中的数据?_Java_Javascript_Jquery_Spring Mvc_Spring 3 - Fatal编程技术网

使用SpringMVC访问外部javascript文件中的数据?

使用SpringMVC访问外部javascript文件中的数据?,java,javascript,jquery,spring-mvc,spring-3,Java,Javascript,Jquery,Spring Mvc,Spring 3,我正在使用Spring3MVC,我有以下课程 外部系统将使用以下URL调用我的应用程序: http://somehost/root/param1/param2/param3 我有一个spring MVC控制器方法,如下所示: public ModelAndView showPage(@PathVariable("param1") String paramOne, @PathVariable("param2") String paramTwo, @PathVariable("param3") S

我正在使用Spring3MVC,我有以下课程

外部系统将使用以下URL调用我的应用程序:

http://somehost/root/param1/param2/param3
我有一个spring MVC控制器方法,如下所示:

public ModelAndView showPage(@PathVariable("param1") String paramOne, @PathVariable("param2") String paramTwo, @PathVariable("param3") String paramThree, HttpServletResponse response) {  
        SomeModel model = new SomeModel(paramOne, paramTwo, paramThree);
       return new ModelAndView("SomeJsp", "model", model);
    } 
SomeModel.java SomeJsp.jsp externalJs.js 在外部java脚本文件中,是否可以获取模型内容


谢谢

在jsp页面中,您可以定义全局js变量并从外部js访问这些变量,如:

jsp文件
普拉卡什,我很困惑。您能给我一些代码片段吗?@user755806:我已经添加了代码片段。
public class SomeModel{
 private String paramOne;
 private String paramTwo;
 private String paramThree;
//constructor
 //setters and getters

}
//In this Jsp i have a div with few elements. Div is not visible by default.
//This jsp has externalJavascript included.
//I enable div and set the data into div elements using jquery.
$(document).ready(function() {

    //Here i need the model returned using ModelAndView
//I can get data from model and set into div elements.


});
<script>
  myModel=[];
  myModel.paramOne='${model.paramOne}';
  myModel.paramTwo='${model.paramTwo}';
  myModel.paramThree='${model.paramThree}';
</script>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

<!DOCTYPE>
<html>
<head>

<script>
  myModel=[];
  myModel.paramOne='${model.paramOne}';
  myModel.paramTwo='${model.paramTwo}';
  myModel.paramThree='${model.paramThree}';
</script>


<script src="externalJs.js"></script>

</head>
<body>
<!--content-->
</body>
$(document).ready(function() {

// myModel will be accessible from here because it's globally declared
   alert(myModel);

});