Why is the JSP command <%=%> getting overlooked within a Javascript statement located inside a taglib tag declaration?

Allow me to provide an example to make this concept easier to understand!

The jsp file...

<%@ taglib prefix ="jam" uri= "http://jam.tld" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="ISO-8859-1"%>
<%
     String targetPage = true ? "toast" : "bread"; 
%>

<jam:text onmousedown="movePage('<%=targetPage%>');" id="<%=targetPage%>"><%=targetPage%></jam:text>

Note - the taglib mentioned is not of my creation and unfortunately, I do not have any authority over it. (It's not actually named jam either :).

This results in the following HTML output...

<td onmousedown="movePage('<%=targetpage%>;');" id="toast">toast</td>

As you can observe: the <%=targetPage%> was only replaced/parsed outside of the JavaScript section?

The compiled jsp file appears as follows:

jspx_th_jam_005ftext_005f2.setOnmousedown("movePage('<%=targetPage%>')");

Does anyone know what could be causing this issue, or how it can be resolved? Why is it that the <%=%> tag seems to be disregarded when included within a JavaScript statement? :)

Answer №1

If you're looking for a shortcut, here's a helpful trick: you can simplify the JS call by removing the JSP tag. It actually makes the code cleaner this way.

<jam:text onmousedown="movePage(this.id);" id="<%=targetPage%>"><%=targetPage%></jam:text>

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

Optimal approach for managing exceptions when working with Q.promise

The method below is used to extract an ID from a given object: module.exports.getId = function(someObject) { var myId = null; return Q.Promise(function(resolve, reject, notify) { // Loop through all the id's someObject.user ...

Displaying a randomly selected value from a database in a JTextField

In my "generator" database, there's a table named "emails" which holds a column storing email addresses. I am looking to create a function that, upon clicking a button, will fetch random data from the email column and display it in a JTextLabel. How ...

Is it possible to have one table nested inside another?

Is there a plugin available that allows me to create a table inside another table, linked by an ID and expandable? Something similar to the example shown in this image. Alternatively, is it possible to generate this automatically using a JavaScript functi ...

How can I add an apostrophe (') into the regex expression within an Angular application?

This regular expression is designed to validate an address input field that can include special characters such as period (.), apostrophe ('), hyphen (-), number, pound sign (#), at symbol (@), ampersand (&), forward slash (/), and spaces. Howeve ...

Tips for linking a dictionary to an Angular <p> tag in HTML

Although I have little experience with angularJS, I am struggling to find a clear explanation on how to bind a dictionary with an html tag so that any changes made in the dictionary reflect in the number displayed within the <p> tag. For instance, if ...

Building a follow/unfollow system in Node.jsLet's create a

I am relatively new to programming and I'm looking to implement a follow/unfollow feature in my application. router.put('/user/:id/follow', auth.verifyuser, (req, res)=>{ user.findById(req.params.id) .then((otherUser)=>{ if(otherU ...

What steps can be taken to ensure that all object properties become reactive?

Let's dive into this simplified scenario: interface Pup { name: string; age: number; } const puppy: Pup = { name: 'Rex', age: 3, }; The goal here is to establish a reactive link for each attribute within the puppy object. The usua ...

What is the process for implementing a dynamically generated template in a Vue.js instance?

Using a static template with a Vue.js instance is straightforward. The firstPlaceholder content gets replaced by the staticTemplate, and the text property renders correctly. However, creating a dynamic template poses rendering issues. The secondPlaceholde ...

Tips for setting up Implicit and Explicit Waits as well as pageLoadTimeout using Selenium

I'm currently questioning the effectiveness of my waiting strategies in my setup. Is this approach correct? Placing it within the @Before("@setup") method, will it work for all Scenarios and Step Definitions executions? Will the driver truly wait each ...

Importing current source files into Eclipse

Struggling with setting up a project in Eclipse with a directory structure of "org.project.file". How do I import the source files into Eclipse while maintaining the directory/path structure? The package used in the source code is org.project.file. When l ...

Incorporating numerous dropdown menus to a table filled with data retrieved from a database

I have implemented a dynamic table that adds a new row at the end when a button is clicked. One of the columns in the table contains a dropdown list, and I want this dropdown list to display values from a database. This is how I am constructing my table ...

The first parameter in Vue router is optional

Is there a way to make the first parameter in my list of routes optional? I want the parameter to change a header in my api calls if it's present in the url, but everything else should stay the same. Instead of creating two sets of routes to handle t ...

The asynchronous callbacks or promises executing independently of protractor/webdriver's knowledge

Could a log like this actually exist? 07-<...>.js ... Stacktrace: [31m[31mError: Failed expectation[31m [31m at [object Object].<anonymous> (...06-....js)[31m[31m[22m[39m It seems that something is failing in file -06- while I am processin ...

What is the best way to turn off ajax functionality when detecting IE8?

Encountering a significant problem where every time the save/cancel button is clicked, IE8 freezes (while Firefox and Chrome work without issue). When JavaScript is disabled in the browser, it works correctly. There is a suspicion that an ajax call linke ...

Save the altered aircraft shapes as JSON files, utilizing the Three.js framework

I've been working on modifying the vertices of a plane geometry in order to create new shapes. However, I've run into an issue where when I export the modified geometry as JSON, the changes I made to the vertices are not included in the exported ...

Efficient Loading of Angular Material Grid Lists

I managed to design a grid page with the help of angular Material Grid list. Is there a method to combine the Material "Virtual Repeat" feature (Lazy Loading on scroll) with the grid list? This would allow for loading more grids as the user scrolls. Any a ...

Using Selenium WebDriver to Perform Drag and Drop Functionality on an Angular/Material Design Website

I've been attempting to automate the drag and drop event using Selenium Java WebDriver on a website built with Angular/Material design. Despite trying numerous approaches, none have been successful - there are no error messages, but the dragging and d ...

Unable to utilize the Reference Variable for accessing methods in an Intellij Maven project

I am a beginner in the world of coding and I will do my best to provide detailed information about my issue. I will include screenshots to show the steps I have taken. To start off, I set up a maven project in IntelliJ. Here's an image of the new pro ...

Pausing in Selenium tests after initializing the webdriver in the current thread

I've been pondering on the issue of selenium testing with the chrome headless variant. It seems that sometimes the test is taking a long time, up to 10 minutes, even though I have set the test timeout to 40 seconds. 15:41:54 INFO: Selenium WebDriver ...

Simulate various beans in a Spring Boot application

In my SpringBoot test, I need to check multiple beans in a uniform way. Instead of creating separate dummy tests for each bean, I want to dynamically fetch and test all beans using ApplicationContextAware interface. @ExtendWith(SpringExtension.class) @Spr ...