首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何将我的ExtWebComponent添加到JSP中?

如何将我的ExtWebComponent添加到JSP中?
EN

Stack Overflow用户
提问于 2019-11-01 20:20:11
回答 1查看 57关注 0票数 0

我想将我的web组件添加到JSP中。我如何连接我的ExtWebComponents来做到这一点?

我的服务器端运行在Servlet容器中。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-11-01 20:20:11

我有一个项目示例,展示了如何做到这一点。客户端是ExtWebComponents,服务器端是Java。

项目备注

  • Maven多模块项目
  • 后端的Java容器
  • 客户端是一个ExtWebComponents项目,只使用pom.xml轻松地将其作为模块导入到IDE中。并启动npm建设。

示例项目

JSP示例

代码语言:javascript
复制
<!DOCTYPE HTML>
<html manifest="">
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=10, user-scalable=yes">

    <title>Sandbox Project</title>
    <link rel="icon" type="image/x-icon" href="resources/favicon.ico">

    <script src="webcomponents-bundle.js"></script>
    <link href="ext/ext.css" rel="stylesheet">
</head>

<body>

Testing
<my-sandbox-view></my-sandbox-view>

<%
    out.write("<h2>Test jsp<h2>");
%>

<!-- The webpacked resource bundle is imported here -->
<script type="text/javascript" src="ext/ext.js"></script><script type="text/javascript" src="app.js"></script></body>
</html>

示例源

客户端到服务器端的资源

您必须告诉webpack将资源复制到您的web应用程序目录中,以便它们可以用于您的Java项目。例如,这就是如何使用自定义插件,然后使用webpack手表。

代码语言:javascript
复制
// This causes infinite loop, so I can't use this plugin.
//  new CopyWebpackPlugin([{
//    from: __dirname + '/build/',
//    to: __dirname + '/../sandbox-server/target/test1'
//  }]),

// Inline custom plugin - will copy to the target web app folder
// 1. Run npm install fs-extra
// 2. Fix the path, so that it copies to the server's build webapp folder
{
  apply: (compiler) => {
    compiler.hooks.afterEmit.tap('AfterEmitPlugin', (compilation) => {
      // Debugging
      console.log("########-------------->>>>> Finished Ext JS Compile <<<<<------------#######");

      let source = __dirname + '/build/';
      // TODO Set the path to your webapp build
      let destination = __dirname + '/../sandbox-server/target/sandbox';

      let options = {
        overwrite: true
      };
      fs.copy(source, destination, options, err => {
        if (err) return console.error(err)
        console.log('Copy build success!');
      })
    });
  }
}

示例源

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58665421

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档