首页 > 解决方案 > 如何将 jsp 字符串传递给角度输入参数?

问题描述

我正在尝试将 JSP 字符串值传递给角度输入参数。

使用“ ng new”,我只需在 index.html 中编辑这一行,就构建了我非常简单的 Angular 项目:

<app-root [jspstring]="<%= jspstring%>"></app-root>

所以我运行“ ng build --prod”,并将所有文件复制到使用 MVC Struts 1.1(不要侮辱我)和 JSP 构建的 Web 应用程序中。

然后我将 index.html 的扩展名更改为 index.jsp 以使用如下 JSP 语法:

<% String jspstring = (String) request.getAttribute("jspstring"); %>

...我想将“jspstring”(用请求属性中的字符串正确填充)传递给“ @Input() jspstring: string;"(在 angular app.component.ts 中正确定义)

然后我用我的struts ForwardAction直接访问index.jsp页面(struts正常运行)。

一切正常(js 和 css),但未设置“@Input() jspstring”。

你有什么解决办法吗?提前谢谢你。

这是 index.jsp 文件:

<html lang="en">
    <head>
      <meta charset="utf-8">
      <title>StrutsWithAngular</title>
      <base href="./">
      <meta name="viewport" content="width=device-width, initial-scale=1">
      <link rel="icon" type="image/x-icon" href="lib/favicon.ico">
    <link rel="stylesheet" href="lib/styles.3ff695c00d717f2d2a11.css">
    </head>
    
    <% String jspstring = (String) request.getAttribute("jspstring"); %>
    <body>
      This work fine: <%= jspstring %>
      ....but angular input param jspstring is not set:
      <app-root [jspstring]="<%= jspstring%>"></app-root>
    
      <script src="lib/runtime.0e49e2b53282f40c8925.js" defer></script>
      <script src="lib/polyfills.8c151b8375e767ff858f.js" defer></script>
      <script src="lib/main.823494c4e9f7a31ecf88.js" defer></script>
    </body>
  </html>

标签: angularjspstruts-1

解决方案


推荐阅读