How to include angular2/4 component in JSP page?

后端 未结 4 1135
孤街浪徒
孤街浪徒 2021-02-10 15:12

I want to add angular component into JSP page, what are the possible ways ?

To Describe more :

I have one application dynamic web application in JSP and another

4条回答
  •  攒了一身酷
    2021-02-10 15:21

    I was recently working on the similar use case where I had to add the angular page on to the JSP page. Based on what I did, this is what you can also do: You can copy and add all and tags to your JSP page from the index.html file that is contained in the build directory of your angular application. In case that your build of the angular application is with --prod option, since the file under your build directory(normally 'dist'), is named with the dynamic hash (this is named this way for cache busting purpose), you need to create a logic which loops over files in the dist folder and find the CSS and js files dynamically based on the extensions of each file and create the corresponding string literal with or based on files type(.js or .css). After this, you need to include those string literals in the JSP file using out.print() statement.

    Then finally you can add your angular component selector like on your JSP page. As you have all the required scripts and CSS already added, it should work without any issues.

提交回复
热议问题