Access View inside WEB-INF using angular.js - spring

I am new to AngularJS. In my project all views html are inside WEB-INF folder, I want to use AngularJS so I have written app.js and controller.js but view is not rendering.
How can I resolve this?

Don't put them in WEB-INF. By design, WEB-INF is inaccessible from the outside. You can put your templates anywhere you want, except WEB-INF.
Or, since you're apparently using Spring, configure it to serve those resources, instead of using the default servlet.

Related

How to deploy Static Vue application with Spring Boot on a Weblogic Server?

I have a Spring boot application deployed on a Weblogic server, and I want to add a Vue/vite frontend to it. I created a Vue project and then built it into static assets. I then placed the contents of the resulting Dist folder (index.html and assets folder) into src/main/resources/static of the Spring Boot project.
Then I generate the war file using Maven, and host that on Weblogic. The Spring Boot section of the app functions as normal, but when I navigate to weblogicurl/myapp/index.html- it is just a blank page rather than the complete frontend I'm expecting. Upon inspection, the blank index.html does have the standard Vue div element with id of "app", so weblogic is detecting and showing the static frontend. However, it is not able to pull any assets to actually display html or use the js - as it is 404ing when index.html tries to pull those built files.
I'm thinking that maybe it's because index.html is trying to pull the js and css assets from /weblogicurl/assets rather than /weblogicurl/myapp/assets but I'm not entirely sure as I'm unfamiliar with the intended structure of a Spring Boot Web app hosted on Weblogic. If that is the case, how would I resolve it? Though maybe it's some other issue, so any input would be greatly appreciated.
I'm assuming that your index.html has src URLs starting with / and that would cause weblogic to look in its default js assets folder. Alternatively, the src might include assets in the URL.
In any cases, you should update these URLs to be relative and correct after build aka remove the starting / and check path from html to js.
Turns out the problem was indeed that it was pulling assets from /weblogicurl rather than /weblogicurl/myapp.
Adding base: '/myapp/' to my vite.config.ts (or vue.config.js for non vite) resolved it.

How to implement Vue.js applications with Spring MVC or other server-sided frameworks?

I've already read the official Vue.js documentation about building app. What I understood is, by using vue-cli, *.vue files are built (or compiled ?) into a javascript file which is injected in index.html file.
What if I don't have any index.html ? In my current application, html documents are built at runtime from jsp template files, how can I have Vue inject js and 'asset' built files into a chosen jsp template ?
Plus, node server should be used in development mod, is this mandatory ?
I would copy the generated javascript file and put it in the public/static folder. Then on the jsps that would use it, just add a script tag that would point to it and the empty div#app.

How to render html page dynamically with all its includes from database

we are developing application in spring boot where the html css and js are gonna render from database or some other storage location like cache.
Is there any framework already existing to implement this?
If yes for render .jsp file dynamically, how to render css and js dependency also dynamically?
This post shows how to implement a Thymeleaf view resolver that gets the templates from database. You can tweak it to your needs (jsp's or whatever)

Add a directory to root of a webapp in Spring

I have Spring + Angular APP.
I want to keep my directory structure as
ROOT
WEB-INF
UI-APP
index.html
css
js
But I don't want to access my application as domain/UI-APP.
I want UI-APP folder to be added / changed as ROOT.
Using welcome file is not the solution because
I don't want my Angular Project to be aware of UI-APP directory meaning I want all my js and html to use relative path.
ie ( if i rename UI-APP to View then also I don't want to change my html and js files. )
Is it possible without container specific way.
All i can think of is creating a servlet to handle all request and return content of file from UI-APP directory or may be Spring Servlet Dispatcher already has an option for it.
I want it to be as generic as possible.
Some Config in web.xml would be best.
Config in dispatcher servlet xml would also be ok.
tomcat, jetty specific configuration is the last resort.

Static content in spring boot....Again

I want to include static content in Spring boot JAR application.
I understood it's recommended to not use /src/main/webapp.
But with IntelliJ, the application run correctly. I tried to change to
/src/main/resources
or
/src/main/public
, but it doesnt work.
/public works, but I dont think its is a good solution.
How I rename static directory and where I have to move please ?
thanks
/src/main/resources is the base folder for all resources. If you place a static|public|resources|META-INF/resources folder inside of it the content should be served (e.g. /src/main/resources/static)

Resources