"Adding a .js file to your Google App Engine project: a step-by-step guide

When working on my app, I encountered an issue with including a separate .js file in my .jsp frontend page.

This is how my directories are arranged:

src
|--->com.stuff
     |--->servlet.java
war
|-->WEB-INF
    |--->pages
         |---->page.jsp
               include.js

Within my java servlet, I use the code:

RequestDispatcher jsp = req.getRequestDispatcher("/WEB-INF/pages/page.jsp");

This code functions correctly, but within page.jsp, I encounter the following issue:

<!DOCTYPE html>
<html>
    <head>
        <title>Page</title>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"type="text/javascript" ></script>
        <script src="./include.js" type="text/javascript" ></script>

    </head>
    <body>
        <h1>Page</h1>
    </body>
</html>

I have tried multiple variations of "./include.js" and consistently receive the error message from firebug:

"NetworkError: 404 Not Found - http://localhost:8888/include.js"

Answer №1

Have you taken a look at the documentation regarding "Utilizing Static Files"? https://developers.google.com/appengine/docs/java/gettingstarted/staticfiles

You really should!

The documentation clearly states that "By default, App Engine serves all files in the WAR directory as static files except for JSPs and files located in WEB-INF/."

In this case, your include.js is placed within the WEB-INF/ directory.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the best way to update auto margins after resizing an element with Javascript?

I'm having an issue with a DIV on my webpage that is centered using margin-left and margin-right set to auto. When I try to resize the DIV, it no longer stays centered on the screen. <div id="content" style="margin-left:auto;margin-right:auto;widt ...

Using JQuery, identify cells located in the first column of a table excluding those in the header section

In the past, I had code that looked like this: $(elem).parents('li').find(...) I used this code when elem was an item in a list, making it easy to reference all items in the list. But now, I've made some changes and decided to use a table ...

Using jQuery, Ajax, and HTML together can create dynamic

Is there a way to run JavaScript functions in an HTML file that is loaded using AJAX? The HTML file contains both text and JavaScript, but only the inline JavaScript seems to work (like onclick="dosomething();return false"). The pre-defined functions wra ...

Setting up an SSL certificate for an Express application: A step-by-step guide

I am currently trying to set up my Express server in order to pass the SSL certificate and transition from http to https. After going through the Express documentation, I still haven't been able to find a suitable solution. While some suggestions lik ...

Is it possible to test code that utilizes a different framework from jQuery using QUnit?

Currently, I am in the process of developing a compact library that is capable of utilizing multiple frameworks (specifically jQuery, Prototype, YUI2). To ensure its functionality, I am conducting tests using QUnit. Nevertheless, one setback is that QUnit ...

Querying Techniques: Adding an Element After Another

CSS <div id="x"> <div id="y"></div> <div> <p>Insert me after #y</p> The task at hand is to place the p tag after '#y', and whenever this insertion occurs again, simply update the existing p tag instead of ...

Passing props dynamically with TypeScript ENUMs

As I begin learning TypeScript with React, I am creating practice scenarios to enhance my understanding along the way. export enum Colors { Blue = "#0000FF", Red= "#FF0000", Green = "#00FF00", } export const ColorComponent: React.FC<props> = ...

Error: The session ID is not currently active

I encountered a problem with my tests failing when running them on TFS, showing the following error: WebDriverError: No active session with ID Failed: No active session with ID Interestingly, these same tests are passing locally. Everything was working ...

Attempting to create a dynamic effect with a div element, where a randomly generated string shifts to the left and new characters are continuously added at the end, resembling a scrolling motion

I recently delved into learning javascript, html, and css on Codepen. I've been working on creating a matrix code rain effect over the past few days. While I do have some experience with other programming languages, I encountered an issue when trying ...

Preventing SVG filters from disappearing during hover with smooth transitions

Exploring new concepts, I have delved into the fascinating world of SVG objects. I recently designed a button with a filter applied to it. However, the designer I am collaborating with has requested a hover effect where the filter (a drop shadow) transitio ...

The Bootstrap 4 card component is a versatile and stylish

Currently working on a display layout using Bootstrap 4, specifically utilizing cards. The issue I'm facing is that the text exceeds the limit of the card, causing it to overflow. Is there a solution to make the text automatically wrap to the bottom ...

Retrieve the row id from the table by clicking on a button in a modal box using jQuery

I am encountering a challenge with a small task due to my limited experience in jQuery. I have a table where each row has an icon. When the icon is clicked, a modal box appears with some content. After closing the modal box, I want to retrieve the table ro ...

How to retrieve values/keys from a JSON object dynamically in JavaScript without relying on fixed key names

shoppingCart = { "Items": 3, "Item": { "iPhone 11 Pro": { "productId": 788, "url": "http://website.com/phone_iphone11pro.html", "price": 999.99 }, "Bose Noise Cancelling Headphones": { ...

employing the dimensions of the browser's viewport within a conditional statement

Recently, I came across this JavaScript code that helps in fetching the current viewport size: //get viewport size var viewport = function(){ var viewport = new Object(); viewport.width = 0; viewport.height = 0; // the more standards compliant browsers (m ...

Having trouble getting my initial Vue.js code to function properly alongside basic HTML

I am in need of assistance with this code as it does not seem to be working properly. I am using an external js file named app.js for the Vue JS code in the index.html file. Here is the code from index.html: new vue({ el: '#app', data: { ...

How do I utilize ng-repeat in Angular to pass a variable that specifies the number of repetitions?

When working on my app, I encountered a situation where I needed to retrieve elements from a database and display them using ng-reat. Everything was going smoothly until I realized that within this list, there was another set of data that required a separa ...

What is the secret behind the functionality of this Jquery dark mode code?

I was experimenting with creating a dark/light mode toggle using jQuery and I came up with this solution One thing that puzzles me is when I remove the 'darkmode' class, instead of adding the 'whitemode' class, it simply adds the attri ...

Implementing a search filter in Vue.js using a nested for loop

I am currently working with a JSON object that contains nested objects and I need to iterate over them to extract data. Everything is functioning correctly, but now I want to implement a search/filter feature where the search is performed on the second lev ...

What is the best way to identify when my custom objects collide with the boundaries of the screen?

I need help detecting collisions between my dynamic cards and the screen boundaries. Currently, when the cards go out of view, I want them to bounce back upon hitting the screen edge. How can I identify these collisions in my code? As of now, the cards ...

Understanding how to implement action logic in React Redux to control visibility of specific categories

Seeking guidance on how to implement action logic for displaying and hiding elements based on user interaction. Currently, all categories and subcategories are shown at once, but I would like them to be displayed only when a user clicks on them. When a use ...