where to put css and javascript files in eclipse dynamic web project - eclipse

I decided to add an external css file for a dynamic web project created in eclipse. If I create "fooStyle.css" and refer to it within a jsp file where should I put the css file in the project folder?
<html>
<head><title>Foo</title>
<link rel="stylesheet" href="fooStyle.css">
</head>
<body>....</body>
</html>
[update]
The below link gives me some idea where to put. It says I should put it under theme, but I am not sure this is a directory I have to create manually under WebContent or at the same level as of WebContent.
http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.wst.webtools.doc.user%2Ftopics%2Fccwebprj.html

Related

Eclipse -The absolute uri: http://java.sun.com/jsp/jstl/core cannot be resolved in either web.xml or the jar files deployed with this application

I read all the posts regarding this error but for some reason it does not work for me...
Here is my folder structure,
I get the error as mentioned in my title,
The code of the if_tag.jsp,
<%# taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
<title><c:if> Tag Example</title>
</head>
<body>
<c:set var="salary" scope="session" value="${2000*2}"/>
<c:if test="${salary > 2000}">
<p>My salary is: <c:out value="${salary}"/><p>
</c:if>
</body>
</html>
The jstl libraries are located in -
C:\tomcat\webapps\ROOT\WEB-INF\lib
If you are running the maven project as dynamic web project on a server within eclipse, then you should follow the following steps!
open the project properties by right click on the project > properties and select Deployment Assembly.
Click add, select Java build path entries, and choose maven dependencies and then click Finish and Apply.
hope, it may work. it worked for me.
JSTL uses different URIs. You just need to get the right version of it.
You could download using JSTL 1.2 or download the JSTL 1.1 jars.
Javaranch has more detailed list of version/URIs.
I just wanted to note that if you have a project that is Maven based, and you import it into eclipse but receive this error absolute URI, then you might need to follow these directions Maven dependencies not visible in WEB-INF/lib (namely the Deployment assembly step)
To solve this issue copy and paste the jstl-1.2.jar file into your WEB-INF/lib folder directory. This will fix your issue.

How to deploy a play framework app and exclude particular resources under "public" directory?

I want to deploy a Play 2 application, my javascript and css files are in the "public" directory, I only want to expose minified javascript files and keep the sources private. How can I achieve it with Play? Thank you in advance.
I only want to expose minified javascript files and keep the sources private.
It is very easy. Look at the documentation where it says:
Any JavaScript file present in app/assets will be parsed by Google Closure compiler, checked for errors and dependencies and minified if activated in the build configuration.
So instead of having the .js files in /public/javascripts/ you place them in /app/assets/javascripts/ and when the application is built you will have both a .js file and a .min.js file available.
You don't have to change your <script/> tag either, just keep it as it was:
<script src="#routes.Assets.at("javascripts/my-javascripts.js")" type="text/javascript"></script>
or
<script src="#routes.Assets.at("javascripts/my-javascripts.min.js")" type="text/javascript"></script>
If you only want to allow the .min.js files to be accessed then you can update the routes file with a regex:
GET /assets/javascripts/$file<.*\.min\.js> controllers.Assets.at(path="/public/javascripts", file)
Now you can to to address http://my.domain.com/assets/javascripts/my-javascript.min.js but not http://my.domain.com/assets/javascripts/my-javascript.js.

eclipse dynamic web project file locations

I'm creating a new dynamic web project in Eclipse and was wondering what best practices are for folder taxonomy. Here's what I believe it is <> are folders. Can someone please verify?
<Eclipse project name>
<src>
-- .java files
<WebContent>
-- .html pages
<images>
<css>
<js>
<META-INF>
MANIFEST.MF
<WEB-INF>
web.xml
<app name>
-- .jsp pages
Here is a sample folder structure of a dynamic web project:
As you can see all static files are placed as sub-folders under the WebContent folder. By naming conventions .css files are places in the css sub-folder. JavaScript .js files are placed under the js sub-folder and any image files such as .jpeg or .png are placed in the images sub-folder. I also have an extra lib sub-folder where I placed an angularjs library to be used.
By default after creation of a dynamic web project your web.xml file looks like so:
`<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.jsp</welcome-file>`
meaning it will first call the listed default name files when you run your application. This is why most projects will name the files as index.html or index.jsp. NOTE: that my index.html file is directly below the WebContent folder and not in a sub-folder
Finally you can call/include your static files (.css .js and image files) from your 'index' file like so:
<link rel="stylesheet" href=css/bootstrap.min.css>
<link rel="stylesheet" href=css/bootstrap-theme.min.css>
<script type="text/javascript" src="lib/angular.min.js"></script>
<script src="js/contactsApp.js"></script>
Also your .java files will properly go in the Java Resources -> src -> {place java files here}
Put your pages under WEB-INF folder, in that way they cannot be accessed directly.
Also look at maven directory layout http://maven.apache.org/guides/introduction/introduction-to-the-standard-directory-layout.html.
To what Aleksandr M said,
WebContent folder:
The mandatory location of all web resources, including HTML, JSP, graphic files, and so on. If the files are not placed in this directory(or in a sub directory structure under this directory), the files will not be available when the application is executed on the server.
WEB-INF
Based on the Sun Microsystems Java Servlet 2.3 Specification, this directory contains the supporting Web resources for a Web application, including the web.xml file and the classes and lib directories.
Source: http://help.eclipse.org/juno/index.jsp?topic=%2Forg.eclipse.wst.webtools.doc.user%2Ftopics%2Fccwebprj.html
I am not sure why having an app-name directory under WebContent would be considered a "best practice".
Other than that, one primary rule you should be following when coming up with a directory structure is to have all static resources under one directory. In your example, I would have a subdirectory called static under WebContent, and place the js, css and images directories under it.
That way, it'd be easier for you to (later on) configure your HTTP server to pick static resources directly from the file system rather than route requests for static resources through the servlet container.
I had this question too and can't comment yet, but Upendra Bittu's answer helped me.
http://help.eclipse.org/neon/index.jsp
Search 'jsp', click on "Creating JavaServer Pages (JSP) files"
Create a dynamic Web project if you have not already done so.
In the Project Explorer, expand your project and right click on your WebContent folder or on a subfolder under WebContent. Note that
if you choose any other folder in which to create the JSP, then it
will not be included in the WAR file that is deployed to the server.
In addition, link validation will not encompass files that are not
under the WebContent folder.
From the context menu, select New > JSP. The New Java Server Page window appears with your folder selected
I'm trying out tutorials and get lost when people don't say where they create their files, and this helped me understand what's going on, so I'm just passing it on.

error in Struts framework settings

I downloaded tomcat, eclipse, Struts framework. Tomcat is working. Where to place eclipse and Struts? I placed eclipse and Struts outside tomcat folder. The needed jar files are stored inside eclipse current folder. I'm getting error.
<%#taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Hello World</title>
</head>
<body>
<bean:write name="helloWorldForm" property="message"/>
</body>
</html>
unknown tag:bean.write
Eclipse is an IDE. It's used to develop Java applications. Not just one application, but several ones. You shouldn't place any app-specific jar into the eclipse folder.
Struts (and not strut or struct) is a web framework. Its jars must be put in the WEB-INF/lib folder of your deployed application. In an Eclipse web project, the location for them is (typically) <yourProjectDirectory>/WebContent/WEB-INF/lib.

SpiffyUI: help configuring existing GWT project; in particular, how exactly is spiffyui.min.js being found?

I feel as if I must be missing something obvious here. The Getting
Started page here http://www.spiffyui.org/?getStarted
says, among other things:
Add the Spiffy project dependency You can have Spiffy automatically downloaded through a Nexus server, or you can manually download JARs
from our downloads page. . . . .
Ok, I just use Apache Ant the way it was configured by the GWT
project generator. I downloaded the two .jar files and told the
build.xml file to copy them into war/WEB-INF/lib when I build.
(also setting spiffyui.sdk at the top)
<!-- Add any additional server libs that need to be copied -->
<copy todir="war/WEB-INF/lib" file="${spiffyui.sdk}/spiffyui-0.7.8.jar" />
<copy todir="war/WEB-INF/lib" file="${spiffyui.sdk}/spiffytasks-0.7.8.jar" />
Reference Spiffy in your HTML Now the CSS and JavaScript files are included in your project when you build. The next step is to reference
them in your HTML file. The Spiffy UI framework includes many
JavaScript and CSS files, but they are all combined into two files for
faster application loading. Reference this one file and the JQuery
library in the head section of your HTML files like this:
<head>
<script type="text/javascript" src="jquery.min.js"></script>
<script type="text/javascript" src="spiffyui.min.js"></script>
...
</head>
Ok, done.
Import Spiffy in your GWT module The last step is to import the Spiffy UI framework GWT module. Add the following line to your GWT
module file:
<inherits name="org.spiffyui.spiffyui" />
Ok, done
That's all it takes.
Really?
So now I am serving html file that refers to spiffyui.min.js as a
local file. It seems to me that I should tell my web server to serve
that file. I could not figure out where I was supposed to get that
file until I looked in the .jar files and found org/spiffyui/public/js/
spiffyui.js . Hmm, well maybe these Java web containers automatically
look for files down in the .jar libraries and serve them??! Sounds
odd, but ok.
I tried running under dev mode and then I manually went to the URL
that the script tag src property should imply:
http://127.0.0.1:8888/spiffyui.min.js
result: 404 Not found
maybe I need to special modified URL for dev mode?:
http://127.0.0.1:8888/spiffyui.min.js?gwt.codesvr=127.0.0.1:9997
result: nope, 404 Not found
What am I missing here?
The magic you're missing is the GWT compiler. When you add the module dependency to your GWT project for Spiffy UI you're giving the framework a chance to be part of your projects complication. Part of that means it will copy the spiffyui.min.js file out of the JAR files and into to the same directory in your project output as the rest of your GWT code.
Once the file is copied out the reference you added to your HTML file works because it can pick up spiffyui.min.js with a relative URL. Once the JavaScript loads Spiffy UI can import CSS and anything else it needs to make the framework run.
I hope this helps,
Zack