I am trying to do first web app with Struts2. How to write data to text file, where it could be placed? I'm using Struts2 with Spring (Tomcat7 and eclipse).
You can write data to a text file anywhere on your file system as long as you have its full path and write privileges, regardless of Struts2 or Spring.
Related
I'm trying to add a robots.txt file to my Spring Java web application, but when I put the file in the web app folder, the text is only visible through localhost:8000/context/robots.txt instead of localhost:8000/robots.txt (the URL that google crawler would check), where I receive a 404 error. I've tried putting the robots.txt file at src, WEB-INF, the project's root folder, etc. with the same results.
I've also tried changing my application-context.xml redirecting "/robots.txt" to my file with <mvc:resources mapping="/robots.txt" location="/robots.txt" order="0"/> for all the previous locations and still doesn't work. The index page of my app would be domain.com/context/firstpage.ac so every page is accessible under that context and as I said also the robots.txt file is showed there when I put it on the web app folder.
Is there any way to separate my robots file from the others and put it at localhost:8000/robots.txt or it isn't possible since my app is deployed under that specific context?
Folder-structure:
I have a xml file which is having all SQL queries. While Application Context gets loaded, from the servlet, I read the file and store it in HashMap which is static and will use that object throught the application.
Now , I migrate to spring mvc . I included the sql xml in resourced folder . I need help to read and use that resource throught the application. Is there any way to handle this.
Thanks.
Is anybody here who know how to create a mapping file from static directory to respond for certain url in Spring Boot?
For example, I have file in directory /resource in Spring Boot structure
resources/static/html/index.html
and I want it to respond to url
/index
No catalogue path, no .html postfix
File index.html is served as default HTML file from certain directory. So if you want to serve it from http://domain:port/index URL, you should place it into resources/static/index/index.html.
As I research more, url mapping is possible only if You use template engine like Thymeleaf and then application will became context aware.
Use Thymeleaf and then add your .html files to resources/templates/ and they will be discovered automatically.
I am working on a web application, developed using spring mvc and server is tomcat. Now one of the requirement is that admin can upload a spring related service configuration file(which is different from the spring service configuration file residing in src code) with some changes because we want to make it configurable. Now server will be restarted to get the modified changes.
Now I am confused about one thing, where I should upload this file(file system?) so that when server is started then configured listener will pick up new configuration file.
Pls suggest solution considering it as enterprose aplication.
Find out the reasonable place to keep your system files, other than in webapps/.
(I had kept next to log folder.)
Use Spring's PropertyPlaceholderConfigurer to read file locations from properties file.
Use same locations and Create ApplicationContext object, in a factory method (You can pass any number of files).
Use getBean on applicationContext object to use beans.
I have an AXIS servlet which deployed on an apache tomcat server on windows.
I wrote a web service which I want to run on AXIS.
When I want to deploy my web service, I make a jar file from the classes, and then I copy them to "axis\WEB-INF\lib" directory. Then I deploy the web service using a wsdd file.
My question is - how can I pass parameters to the web service, and how can I read them?
The only web.xml file that I have, is the AXIS web.xml file. Should I put them there?
I came across with exactly same issue. I have a not so perfect solution. I am using a properties file to store params and access this properties file in the service classes. I am facing problem when I put all my classes in to a jar file. I am able to access properties file in my service class if I place properties file inside the jar file. I am unable to access properties file (without hardcoding the path) when I place it outside jar file. For maintainance point of view it is good practice to keep properties file accessible easyly.
-Rao