I am starting to build a Spring Boot web application on top of the Dave Syer's example here. He uses plain html files with AngularJS, that's why he has a file structure like this:
Everything is under static folder. Since the example application is really small, he has created a folder for each page (which i will definitely change in the future).
But i also want to use Thymeleaf and it uses the templates folder as default, as the spring boot defines this default property:
spring.thymeleaf.prefix=classpath:/templates/
Now i do not know if i simply should overwrite that prefix property in my application.yml to sth like spring.thymeleaf.prefix=classpath:/static, or create a template folder and move all my html files in that folder, leaving just the JS files in static. What is the best way of having this combination?
Related
I have some CRUD app that connected through hibernate with the database. There is one JSP file in views. Everything is configured in the config XML file. But CSS still doesn't work.
My app running on IntelliJ IDEA 2019.1.2, MySql 8, Spring 5, Tomcat 9. I tried a few different ways to set up in JSP file path to CSS files. But the result always the same. Everything working, but without styles.
servlet config
project structure
jsp file
result
In the png you it seem you are using resourses instead of resources. Also verify in developer tool of your browser the name of resources folder. You can go to sources tab(chrome) or debugger(firefox) and check the folder structure.
I am developing a website using angular6 and spring boot with microservice architecture.
I have got the UI from designer team in the form of HTML, CSS, and JS file, whose structure is attached here HTML and CSS files
Also, I had created a angular6 project named DIS, whose structure is attached here Angular6 project
What will be the best way to start with angular 6?
How to include these files in angular6 project considering microservices architecture?
If i understood your question correctly.Yes you can do that.
Step 1: You need to create the Necessary components, Modules needed to build your website.
Step 2: Replace the components with the necessary HTML file and CSS file. As you generate a component with CLI you should have those 2 files just replace them.
When you have global CSS files that can be shared among other files as well. You can configure using Angular CLI.
Regards to microservices architecture, that does not have anything to do with your front end applicaiton, its totally on the server side. But you can consider while creating the components based on the services you have.
ng new ng6-proj --style=scss --routing
Just make changes in the main style.scss that will apply globally.
Images you can keep it anywhere, you just need to use it by providing its path
My Java project has multiple JSP (view) pages, which either insert into or query a database. I created the main page and links to each JSP.
I am unsure whether I should put each component of the project (MVC pattern with jsp, servlet, a Java file) into its own web application and its own war file for uploading to the web server. Is this a proper way to build my web project?
If I did this, each component/application would need their own JDBC driver, which seems redundant. I could also group the insert pages together in one application and the query pages in another - would that be a better way to proceed?
I don't see any problem building your war like that, but I prefer using some kind of building tool like Maven, Gradle, etc..
Anyway, If it is a simple dynamic web project with eclipse, you can just put your jdbc driver under your WebContent -> WEB-INF -> lib.
This way, the jdbc driver will be available in your classpath so that basically every java class in your project will be able to use it.
Currently I´m trying to learn Angular JS, but firstly I want to setup my environment with Spring mvc.
At the moment I only want to work with rest, but I have a doubt for what is the best way to place the resoucres in Spring MVC
My simple applicaction has this squeleton:
my-simple-app:
src
main
java
resources
webapp
resources
WEB-INF
If I want to put the app folder from the angular-seed, what is the best place to put it?
I tried to put in src/webapp/resources/app but then I have to move the html files to WEB-INF?
How was your skeleton in your angular-js spring mvc applications?
What is the best way to do the redirect to the app/index.html? to the welcome file and then work only with angularjs $routeproviders?
Thanks!
As far as I can understand, your Front End technology is Angualar JS and your Back End technology is Spring MVC.
I'm a Front End developer and hence I can provide you the advice on the structure of your HTML, CSS, and Javascript.
Here are my recommendations:
Mode Of Communication Between Front End and Back End: JSON (Should be strictly followed for MVC Pattern)
File Location: All your Front End files should be in WEB-INF folder with this structure:
WEB-INF/Assets: All your JavaScript Files, JavaScript Libraries, Images, CSS etc. Should Be Places Here. You Can Open A Separate Folder Each Resource Type Inside Assets
WEB-INF/JSP: All Your JSPs should be placed here. As Angular's greatest strength is Single page Application, you can create one JSP per main page and place them here
WEB-INF/HTML: All the static resources that would be injected into the JSPs using <ng-view>or <ng-include> can be placed here
Hope this helps!
The easiest way to get going is to take all the files in the angular-seed/app directory and copy them into your src/main/webapp directory. After copying these files, you should be able to redeploy the app and have a running sample.
Most servlet containers will include index.html as a default welcome file. If yours doesn't, you can add that config in web.xml <welcome-file-list>.
The WEB-INF directory is for web resources that should not be exposed directly to the web. web.xml is a example of a file that should not be exposed to remote users. In this case, it's safe to expose all of the app's resources directly to the web; thus you don't need to place the resources under WEB-INF.
I recommend this structure for your project:
my-simple-app:
src
main
java
controller
MySpringCtr.java
models
Person.java
House.java
*.java
webapp
WEB-INF
resources
css
style.css
*.css
js
angularCtr.js
*.js
pages
index.jsp
*.jsp
mvc-dispatcher-servlet.xml
web.xml
I found a tutorial for beginners which explains step by step how to combine SpringMVC and AngularJS, you can find the tutorial and the complete code in this blog I hope it will be useful :)
I need to make a link in my Java Spring application that will allow the user to download a CSV file . I have the CSV file in my project's root directory and I have an tag in my view that runs a Javascript function when it's clicked. Is there any way I can use either Javascript or the Java Spring framework to allow the user to download the CSV file? I'm a noob Spring user/developer so any help is appreciated. :)
Put the file in your WebContent (or whatever you call the web resources directory) and link it directly. Everything below WebContent (but not in WEB-INF) is accessible in your context root.
So file WebContent/test.csv is accesible with relative url /test.csv.