javascript - Including Javascript code from a JSP file
问题描述
I have a JSP file that gives me a bunch of JS code that I need to put in my view page (particularly in my JSP file that is the view for the current URL. Using Spring MVC) . Is there a way for it?
I have already tried a bunch of suggestions from here: Including JSP code from another JSP file correctly and here https://coderanch.com/t/596663/frameworks/Calling-jsp-include-tag-javascript but none gives clear answer on it. When the view is rendered after hitting the controller it just gave a plain JS code in the window instead of embedding it as JS code.
<html>
<head> </head>
<script type="text/javascript">
<jsp:include page="./myJSPfiles/MyJSPfileforScript" />
</script>
</html>
As I said, it just gives plain JS code in the browser instead of embedding it. I am fairly new to JSPs in general. Any suggestions?
解决方案
使用类似下面的代码行。
<script type="text/javascript" src="${pageContext.request.contextPath}/js/index.js"></script>
推荐阅读
- java - 如何将 IntStream 转换为 List
? - javascript - Angular 多项目 tslint 规则配置
- html - VS Code 2017“本地主机拒绝连接”HTML文件
- python - 如何阻止信号到达自定义插槽
- python - Python 中的错误:未定义名称“df”
- junit - 带有 Spring JdbcTemplate 的 SimpleJdbcCall 的 Mockito
- python - 应用具有混合布尔值和数值的 pandas GroupBy
- reactjs - 是否聚合了多个 this.setState 调用的状态更改?
- javascript - 仅在 wordpress 简码页面上调用 js 方法
- android - 如何检索用户通过颤振谷歌放置自动完成屏幕选择的位置,以便创建路线?