Get project location from controller [duplicate] - servlets

This question already has answers here:
Recommended way to save uploaded files in a servlet application
(2 answers)
Simplest way to serve static data from outside the application server in a Java web application
(10 answers)
Closed 5 years ago.
Question 1
Here's my project folder,
How can I call images folder from UploadContoller?
I already tried with
request.getServletContext().getRealPath("/images");
But it didn't work.
Question 2
How can I call images > a1.jpg from view > a..jsp?
I already tried with
<img src="/images/a1.jpg">
But it didn't work
SECOND PART
The problem is ok only when i strore my project like (C:\myproject). The problem is When is save my project in other location like (D:\NewFolder\myproject).
Way 1
request.getServletContext().getRealPath("");
--> C:\SpringToolSuite\sts-bundle\pivotal-tc-server-developer-3.2.2.RELEASE\base-instance\wtpwebapps\myproject\
Way 2
request.getContextPath() + "/images/";
-->/myproject/images/
Why i cannot file my project real location.
Right Now, my project is under
C:\Users\Star\Downloads\myproject

request.getContextPath()
the above line will give you the context path of your project which is also known as the root of your file tree. Navigate from there.
Answer 1
request.getContextPath() + "/images";
Answer 2
<img src="<%= request.getContextPath()%>/images/a1.jpg">

Related

How to Create Dynamic Routes in Next.js [duplicate]

This question already has an answer here:
For Next.js Dynamic Routes, it is possible to combine a string with a [slug]?
(1 answer)
Closed 3 months ago.
How Add flexibility to my routing with a quick spot of URL inspection?
I want an address for the product details page, part of which is static and part of which is dynamic:
www.shop.com/product-{productid}-{productname}
like the :
www.shop.com/product-1-applewatch
www.shop.com/product-9-maclaptap
Is this possible in next.js?
Thank you for reading the question.
I found this too but it didn't solve my problem:
https://www.makeuseof.com/nextjs-dynamic-routes-create/
Follow your requirement, you can generate some url be like these:
www.shop.com/product/1/applewatch
www.shop.com/product/1?productName=applewatch
or www.shop.com/product?productId=1&productName=applewatch
Reference: https://nextjs.org/docs/routing/dynamic-routes

Use [slug] as index also in Next [duplicate]

This question already has an answer here:
point /username to /[user]/[tab].js and not [user]/index.js in nextjs
(1 answer)
Closed 9 months ago.
I'm exploring Next with an project, and I'm trying to handle all the routes with one file only. In this case: [slug].tsx so that means me to remove the index.tsx, I tried and didn't work, what do you think can be the way to achieve that.
As already mentioned, you can use an optional catch-all route.
So, rename your [slug].tsx as [[...slug]].tsx, so it will catch also the root without a slug.
Then delete your .index.tsx file.

Process.Start does not work in asp.net [duplicate]

This question already has answers here:
System.Diagnostics.Process.Start not work from an IIS
(6 answers)
Closed 6 years ago.
I have a very simple code, which I am using to test if I can open a specific file. Till now, this is the code I have
string filename = "C:\\anu.txt";
Process myProcess = new Process();
myProcess.StartInfo.FileName = filename;
myProcess.StartInfo.UseShellExecute = true;
myProcess.StartInfo.RedirectStandardOutput = false;
myProcess.Start();
This code starts a notepad process perfectly, but as user "DefaultAppPool". So, I can see the process in Task manager, but the notepad window doesn't show up. I have no idea what I can do here to fix this. I tried running it as different user, but it still shows up with "DefaultAppPool" user id.
Edit:
Apparently this is a security feature in Vista and higher. :/ So, can't do this anymore. Oh well, time to find a workaround.
You don't need to write that much of code. You can open a text file just by a single line
Process.Start(#"C:\Users\ankush.jain\Desktop\test.txt");
Process exists in System.Diagnostics namespace.

Upload file with CMIS Service on st:site

I have been uploading files to Company Home pretty easily with this url:
http://myhost.com:8080/alfresco/s/api/path/workspace/SpacesStore/app:company_home/children
Now I am trying to upload to a folder within a site
http://myhost.com:8080/alfresco/s/api/path/workspace/SpacesStore/app:company_home/st:sites/cm:mysite/children
And keep getting this
Cannot find object for NodePathReference[storeRef=workspace://SpacesStore,path=app:company_home/st:sites/cm:mysite]
Am I missing a special way to declare the path of a site?
i'm not sure how you are uploading to that path but i suppose you need to go into 'documentLibrary' of the site
http://myhost.com:8080/alfresco/s/api/path/workspace/SpacesStore/app:company_home/st:sites/cm:mysite/cm:documentLibrary/children
I found out that there are 6 webscripts related to file manipulation, and it seams each one takes the path in a different way.
I ended up using
http://example.com:8080/alfresco/s/cmis/p/Sites/mySite/Test/children
This particular service it takes Display Names as path segments, and the p itself represents the Company Home segment
I also obtained the same results with this one
http://example.com:8080/alfresco/s/cmis/s/workspace:SpacesStore/i/2aa692bd-0dab-4514-a629-ad36382189f2/children
Which as you can see takes nodeRef Ids as parameter.

Get types in assembly: ReflectionTypeLoad Exception [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
How to reproducably cause / provoke a ReflectionTypeLoadException?
I wanted to get all types in a loaded assembly.code snippet is as follows
Assembly assemblyObj = Assembly.LoadFile(#"D:\abc\abc.dll");
IList<Type> types = assemblyObj.GetTypes();
when i run im getting ReflectionTypeLoadException.What is the mistake in the code.
As you can see in my answer to the question linked as duplicate, the problem most likely is, that "abc.dll" contains a class that derives from a class in a referenced assembly and that referenced assembly doesn't contain that base class, because it has the wrong version.

Resources