How to read & write in a properties file with javascript - javascript

I'm working in a JEE web project and i have a problem, i would like to read and write into a properties file which is located into WebContent/WEB-INF/classes folder and i need to do this with javascript, do you have an idea how to do that ?

Assuming you mean JavaScript on the client: Create an endpoint that the JavaScript code can post to via ajax, and have servlet code handle the post by updating the properties file.

Related

Search through files in path using only javascript

I'm coding a webpage that needs to read some data from different csv on a path depending on the country of the user.
the path is something like this:
./csv/m2-2022-10-25_13_45_55_es.csv
m2-2022-10-25_13_45_56_fr.csv
m2-2022-10-25_13_46_04_it.csv
etc
And those files will be replaced regularly, the only that we'll always have is the country code (es, fr, it, etc).
So, what I need is to list all the files on the path to an array, and loop through the array to find if the last characters of the filename are $countryCode + ".csv", and there run some code.
But I can't find how, all the solutions I find are using Node.js, but are there a solution using only Javascript (or jQuery)?
Regards!
You cannot use pure Javascript to do that, because if you wanted to search files in your computer only using javascript, it would be a huge security breach.
You must use node.js to open files but you can make an API to your nodejs file from your javascript and you can send as a response the content of your file.
Here some links that might help you :
FS : https://nodejs.org/api/fs.html
NodeJS api : https://medium.com/swlh/how-to-create-a-simple-restful-api-in-node-js-ae4bfddea158
You can check a similar question here:
Get list of filenames in folder with Javascript
You can't access to filesystem from the frontend, this it would be a huge security breach, because anyone could access to your filesystem tree.
You have to do a function in backend to build the array you want and send it to frontend.
If you create a function in backend file that returns the array of files in the folder, you can call it from the frontend via XMLHttpRequest or Fetch to get the array in frontend and be able to use in your js file.

How to read a value from properties file in a javascript file

I have a spring-boot project which serves angularjs. Both the front-end and back-end code are in the same project.
In my angularjs service.js files I am calling the back-end service.
I have different urls in the different properties file. I want to read them as per profile selection. I know how to read properties file in a Java class but I am not sure how to read values from properties file in a javascript file.
As shown below:
Some options:
create a separate config.json for your angular APP (manage it manually).
use maven resource plugin to filter placeholders for your config.json file (automated). E.g. read in one place and substitute in another (but I don't like this way).
Or create an API to return data from from your properties file as JSON.
https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html

Apache NiFi: read json file in ECMAScript

I am new to NiFi. My question is how can we read json file in ECMAScript while using excute script process. I want to load json file with mapping json for schema mapping.
I have an post on my blog about how to read in a flow file containing JSON using ExecuteScript with ECMAScript:
http://funnifi.blogspot.com/2016/03/executescript-json-to-json-revisited.html
There is also another StackOverflow question similar to your use case of reading in a mapping file and applying it to incoming data (using Groovy):
Apache NiFi ExecuteScript: Groovy script to replace Json values via a mapping file
Not sure if this helps too but I have another post on validating JSON with ExecuteScript (but Groovy not ECMAScript) using JSONSchema: http://funnifi.blogspot.com/2016/05/validating-json-in-nifi-with.html

how do i access server data in separate js file

aspx file
string firsrName="jafer";
myscript.js
GetMyName();
function GetMyName() {
alert('<%=firstName%>');
}
I am not getting my value
The line alert('<%=firstName%>'); use the Web Form Page syntax. It is actually not possible to get the value like this because this syntax cannot be used in external JS files.
The simpliest (but not cleanest) method is to write the JS method into the layout file or another aspx file.
Read How to get asp.net client id at external javascript file
You could make a global variable in your aspx page and access it in your js using window.objectName

worklight adapter load another java script

Inside HTTP adapter, I am getting JSON object back from REST service. I need to do some parsing of the reply before returning it back to the client.
I figured I can have another JavaScript file to do the parsing, so not to clatter my adapter.js too much.
What I don't know is how to make the 2nd java script file available in my adapter JS.
On client side I would use something like $.getScript("some.js");
JAVA classes can be accessed simply with classpath.className, but I can't find any references on how to load another Java Script file!
Please, help!
You cannot have additional JavaScript files referenced from adapter's JS.

Categories

Resources