Spring MVC resources not being mapped - spring

my folder structure
enter image description here
And my code in the JSP page is
<script src='${pageContext.request.contextPath}/AppNameController.js'/>
I'm still getting 404 error

You have the prefix set to /WEB-INF/jsp but looking at your project structure your index.jsp is only within the /WEB-INF folder rather than inside the /WEB-INF/jsp folder.
Also change to:
${pageContext.request.contextPath}/resources/scripts/AppNameController.js

Related

css file not found - asp.net core web application

I have created an asp.net core web application (I started with the Empty option) and I am building it step by step. It seems my css file is not being read or found though.
When I launch the application I can see that my html page does not look as it should be and when I use the developer tools in edge under the console there is an HTTP404: NOT FOUND - The server has not found anything matching the requested URI (Uniform Resource Identifier). GET - http://localhost:8888/css/site.css error which would indicate my css file is indeed not being read or found.
Now, my css file is under a folder called "css" which is in the root of the project. When I say root I mean that I have just created a folder called css and the path is the same of Program.cs or Startup.cs. There is no wwwroot in my project (seems that asp.net core 2.2 has removed it by default?) and the css folder is not there. As follows the code from my html page, I have tried to add the ~ before the "/css" but still nothing.
<head>
<link href="/css/site.css" rel="stylesheet" />
</head>
If you would like that static files to be served outside of the web root (for example in a folder named MyStaticFiles) and it has the structure like
-YourProject
--MyStaticFiles
---css
----site.css
--Program.cs
--Startup.cs
You could use app.UseStaticFiles, refer to Serve files outside of web root
public void Configure(IApplicationBuilder app)
{
app.UseStaticFiles(new StaticFileOptions
{
FileProvider = new PhysicalFileProvider(
Path.Combine(Directory.GetCurrentDirectory(), "MyStaticFiles")),
RequestPath = "/StaticFiles"
});
}
Then you could get the css from http://localhost:8888/StaticFiles/css/site.css
or <link rel="stylesheet" href="~/StaticFiles/css/site.css" />
It is happening because environment webroot is different than the css folder is currently in. You have to change the webroot or move your css folder to current webroot.
Normally the wwwroot folder is set at environment webroot

keeping safe assets folder in codeigniter

Hi i have this assets folder which has the following folder inside of css, images, uploads, and js folder i put the assets folder outside application. Im wondering that how could i keep it safe so that when users tried to type in the url like for example http:/test.com/assets it will redirect to application folder or somewhat it will says page not found. Cause ive noticed that when i type in the url http://test.com/assets it will go to the assets folder and which is vulnerable and people could see all the folders in the assets folder. can someone help me figued this thing out? Any help is muchly appreciated.
if you want to secure you folder then do one this create html file like this
<html>
<head>
<title>403 Forbidden</title>
</head>
<body>
<p>Directory access is forbidden.</p>
</body>
</html>
and save it as index.html and put it on your assets folder whenever some try to access your url http://test.com/assets then this index file will execute and its shows Directory access is forbidden.

JSF Load uploaded images from nested subfolders

In my web application, I want to upload images and hence present them using p:graphicImage. I store the uploaded images outside the web app – in particular at E:\webapp\upload. Note that my tomcat server is installed on E: volume. I have created an ImageServlet to read the images as described in http://balusc.blogspot.com/2007/04/imageservlet.html.
I added the following configuration to my web.xml file:
<servlet>
<servlet-name>imageServlet</servlet-name>
<servlet-class>utilities.ImageServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>imageServlet</servlet-name>
<url-pattern>/upload/*</url-pattern>
</servlet-mapping>
I can access the images from the index.xhtml page using “upload/imageName.ext” eg:
<p:graphicImage value="upload/flag.gif" />
This jsf code is correctly converted into the following HTML code:
<img src=”http://localhost:8080/MyApp/upload/flag.gif?pfdrid_c=true”>
However, I want to be able to access images from pages which are contained into subfolders. Eg I have one page which is located at “admin” subfolder:
http://localhost:8080/MyApp/admin/language.xhtml
Inside that page, the same jsf code is converted into:
<img src=”http://localhost:8080/MyApp/admin/upload/flag.gif?pfdrid_c=true”>
which is wrong.
In other words, it looks for the images at “E:\webapp\admin\upload” directory which does not exist and hence nothing is displayed. I can clearly write the following code:
<p:graphicImage value="../upload/flag.gif" />
to make it work but I consider this as a bad practice because I will have to adopt the path each time I am in a different subfolder hierarchy (consider for example the problem of nested subfolders).
I am wondering if there is any way to just specify the relative path of the image eg “upload/flag.gif” regardless of subfolder hierarchy.
Thanks in advance!
Just let the path start with / to make it relative to the context root instead of the currently opened folder.
<p:graphicImage value="/upload/flag.gif" />

Spring web development images

Can anybody tell me or give me a link to go to which can tell me how to implement and display images step by step (I'm only beginning) on a webpage from a spring project
I'm using IntelliJ
Thanks
What's the URL of the page? The one that appears in the location bar of your browser?
That is the URL to which relative locations are resolved in the HTML code. So, if the URL is http://localhost/MyApp/foo.html, and the URL of the CSS inside the HTML code is ../../css/style.css, the absolute URL where the browse will try to find the CSS will be http://localhost/MyApp/../../css/style.css, which doesn't make sense.
I prefer always using absolute paths for images and CSS files (and other resources). Using JSTL, that makes it like
<link href="<c:url value='/css/style.css'/>" ...
The <c:url> tag takes care of prepending the application context (/MyApp) to the path.
Note that relative paths inside CSS files are not resolved relative to the page URL, but relative to the location of the CSS file itself. So the path in your CSS file is correct.

where should I add external file to view in CI

I'm trying to make view page in CodeIgniter,So I create it and in Controller it loads complete.
but when I add images and jQuery to it,they will not be loaded.
I made sub folder in view folder by name of Files and add to view for e.g like that
img src="Files/01.jpg" but it will not be shown.
where should I place them?
I usually make a folder called files in the main directory (where system and application reside), and then link to them using base_url().
In your case, this would become
<img src="<?= base_url(); ?>/files/01.jpg" />
Hope that helps.
When your view loads, the file paths will be relative to the directory the CodeIgniter index.php file is located in. If this is also the root directory of your site, you can refer to it in this way: <img src="/Files/01.jpg" />

Resources