How to change path of welcome html file - javascript

I have created Dynamic web project and it has .html, .css and .js files. I group these file in respective folders like .js file in javascripts folder and .html file in views folder but i don't able to access these file in project. I used eclipse IDE for this. Is there need to configure path for these folder?

You need to put the JSP file in /index.jsp instead of in /WEB-INF/jsp/index.jsp. This way the whole servlet is superflous by the way.
WebContent
|-- META-INF
|-- WEB-INF
| -- web.xml
-- index.jsp
If you're absolutely positive that you need to invoke a servlet this strange way, then you should map it on an URL pattern of /index.jsp instead of /index. You only need to change it to get the request dispatcher from request instead of from config and get rid of the whole init() method.

These are not Java source files, so it makes no sense to configure them as such. By default in a Dynamic Web Project you only see the src folder under Java Resources. Other folders will be listed at the bottom of the tree. This is by design.
Or if you meant, that you do not see them when you move into the folder by an external file manager: press F5 on the project.

Its based on from which file you are trying to access those files.
If it is in the same folder where your working project file is, then you can use just the file name. no need of path.
If it is in the another folder which is under the same parent folder of your working project file then you can use location like in the following /javascript/sample.js
In your example if you are trying to access your js file from your html file you can use the following location
../javascript/sample.js
the prefix../ will go to the parent folder of the file(Folder upward journey)

I got answer to my question...
Now my directory structure is
WebContent
--javascripts
--stylesheets
--viwes
--META-INF
--WEB-INF
Note: view contain html files
To change path of my welcome html file i made bit change in web.xml present in WEB-INFfolder.
<welcome-file-list>
<welcome-file>/views/welcome.html</welcome-file>
</welcome-file-list>

Related

What is the use for the special "public" folder in a Meteor app?

I'm currently using Meteor and trying to learn more about the framework. In the documentation about special directories the following is said about the public/ special directory:
All files inside a top-level directory called public/ are served as-is to the client. When referencing these assets, do not include public/ in the URL, write the URL as if they were all in the top level. For example, reference public/bg.png as <img src='/bg.png' />. This is the best place for favicon.ico, robots.txt, and similar files.
My question is: since I refer to files inside of public/ directory as if they were located in the root folder of my application, what's the different between putting the files in the public/ folder and in the root folder? Or is it just for organization sake?
Also the documentation I quoted above makes some examples using assets (some pngs and favicon.ico) and no JavaScript or HTML files. Am I able to put some JavaScript code in there and then import them in another file by referencing as if this code was located in the root of my app? Or is the public/ directory somewhat made only for assets?
I failed to find any docs that explains what is done to files inside this directory in detail (I only found what I quoted above). So if any documentation of that kind is available it would help a lot!
My question is: since I refer to files inside of public/ directory as if they were located in the root folder of my application, what's the different between putting the files in the public/ folder and in the root folder? Or is it just for organization sake?
Just because you can reference or "import" a file from public/ doesn't mean it functions in the same way to how a normal file import would work. Files located in public gets served as is without being minified/run through the Meteor pipleline. Second, these files are accessible to the client which makes sense given how'd import them without preceding slashes and keep them mostly to serve stuff like favicon and what not.
So in a sense, such files within public are made available within relation to your client bundle/code whilst not being a part of them, get it?
This way of serving assets isn't unique to Meteor, even React has a public directory.
Also the documentation I quoted above makes some examples using assets (some pngs and favicon.ico) and no JavaScript or HTML files. Am I able to put some JavaScript code in there and then import them in another file by referencing as if this code was located in the root of my app? Or is the public/ directory somewhat made only for assets?
AFAIK, you can have files of any type in public but since
It's served as is to the client, meaning it's exposed to the public
It doesn't get minified (i.e being part of the final application build code)
You're advised to not have any of the application code within this directory.
The Public folder is how you serve your static files, when you put a file in your root folder it will not be sent to the client by default and you can't use it in your css, when you put that file (say an image) in your public folder you can use it from the css and refer to it as if it was in your root folder, so if I put a.jpg in the public folder I can use url(/a.jpg) in my css, that won't work if a.jpg is simply in your root folder, that's what the docs mean when they say it's served as if it was the root folder.
unlike in Rails, Meteor initiatives don’t have a rigid document structure and you are quite a whole lot free to prepare your projects as you want. a few folder names but have unique which means, and documents within them will be dealt with in a different way.
consumer
files here will be loaded at the client simplest. files in that folder don’t need things like Meteor.isClient.
server
Loaded on the server best, duh! No need for Meteor.isServer whilst files are in that folder, the client won’t see these files.
public
This directory is for property like photographs. on your initiatives, you reference stuff in the public folder as if they have been in the root folder. as an example, when you have a report: public/nude.jpg, then for your app you include it with .
personal
files only available at the server facet thru the assets API.
checks
documents in there received’t be loaded anywhere and are used for checking out your app.
lib
documents in that folder are loaded earlier than whatever else, which makes it the best listing to vicinity the distinct libraries used on a undertaking.

Flask js files not loading due to template folder and static folder file structure

So I'm trying to make a website where I'm able to just drag and drop folders containing HTML, js, and CSS files into a "library" directory and have those files served on my flask app. There's one big problem I haven't been able to get over. The problem is that all of these HTML files link to their respective js files using relative paths. For example:
<script src="js/keyboard_input_manager.js"></script>
and these files are 2 folders deep into my (combined) templates/static folder. I could fix this by doing
<script src="library/2048/js/keyboard_input_manager.js"></script>
but that is very tedious, especially when working with so many files.
TLDR: If I were to run my flask app and load a template, it wouldn't load any js or CSS because of relative paths.
Is there any way to go about this without individually changing each path to relate to the templates folder?
Example of my current filesystem:
-FLASK PROJECT
|->library (templates/static folder)
| |->2048
| |->index.html, index.css, index.js
| |->Game2
| |->index.html, index.css, index.js
|->main.py
What I've Tried:
Using Blueprint but I can't create a whole blueprint for every file?
Messing with paths of template folder and static folder
Flask Noob - Please let me know if I'm leaving out any helpful information :) Thanks

Location of JavaScript files in ASP.NET Core Areas

I am creating an ASP.NET Core application that will contain several areas.
Where would I add JavaScript files that are specific to a certain area (usually I put them into the wwwroot\js Folder. Is there something like this for an area?)?
"Where would I add JavaScript files"? Answer is you can choose your location based on your requirements and convenience. Default location is content root i.e. wwwroot folder and its subfolders however ASP.Net Core doesn't stop you from placing those static files outside "wwwroot" folder. However if you want to place it outside default content folder i.e. wwwroot you need to tell asp.net core where your content files are located. Way to tell asp.net core is configure StaticFiles middleware as follows:
app.UseStaticFiles(new StaticFileOptions()
{
FileProvider = new PhysicalFileProvider(
Path.Combine(Directory.GetCurrentDirectory(), #"MyStaticFiles")),
RequestPath = new PathString("/StaticFiles")
});
Here MyStaticFiles folder is outside wwwroot and located just inside your project directory.
Now if you want to access any file inside MyStaticFiles folder then it will be using following path.
http://<myapp>/StaticFiles/myscript.js
Note "StaticFiles" in above path and in middleware configuration.

Unable to find bower_components in the directory above

I have the following directory structure in one of my projects:
/web
/bower_components
/bootstrap
/jquery
/typeahead.js
/views
/index.jade
I'm trying to use these components from my index.jade file in the following way:
link(src='../bower_components/bootstrap/dist/css/bootstrap.min.css', rel='stylesheet')
script(src='../bower_components/jquery/dist/jquery.min.js')
script(src='../bower_components/typeahead.js/dist/typeahead.bundle.min.js')
but it doesn't work (there's no bootstrap-related styles on this page and jQuery code doesn't work).
Why? What am I doing wrong? How can I fix it?
Should I refer to these components in a different way?
Should I place bower_components directory in another folder?
You probably need to change the file path to be relative to where you are compiling the jade file to.
For example, if you render the jade like this:
/web
/index.html
the source paths would be
link(src='bower_components/bootstrap/dist/css/bootstrap.min.css', rel='stylesheet')
script(src='bower_components/jquery/dist/jquery.min.js')
script(src='bower_components/typeahead.js/dist/typeahead.bundle.min.js')

serving static content in code structure generated by yeoman for angular fullstack

I am following the code structure generated by yeoman for angular fullstack.
I want to include a script called core.js in file called app.html.
<script src="core.js"></script>
I do not see express.static anywhere in this for serving static files.
I tried using it but it did not help.
It can not locate it and gives 404.
How do I get around this ?
It had happened before as well but I could get around it by using express.static and serving files from location pointed by it.
It did not help this time though.
Update:
I have app.html in folder called Music. In same folder, I have a sub folder called js where I have placed my core.js file that is to be included in app.html. I tried to access it using absolute as well as relative path but did not help and still gives 404.
In angular, the scripts go in the relevant subfolder of /scripts. Either in /controllers, /services/, /directives, etc. You then reference them in your html as such:
<script src="scripts/controllers/core.js"></script>
As for express.static, express is a NodeJS wrapper for HTTP. So that will be the service you create that lives on some Node server remotely. express.static allows the Node server to deliver static content files from the file set at the remote server. It does not go in your angular application.

Categories

Resources