Is there a way to identify the specific Struts action being rendered in my JSP file?

One thing I am struggling with is creating a menu that highlights the current page when navigating through my site. For example, if I am on Page 1, I want the "Page 1" link in the menu to stand out. I have been attempting different methods found on Stack Overflow, but none seem to achieve the desired result.

req.contextPath: ${req.contextPath }<br/>
req.requestURL: ${req.requestURL }<br/>
pageContext.request.requestURL: ${pageContext.request.requestURL }<br/>
pageContext.request.requestURI: ${pageContext.request.requestURI }<br/>
pageContext.request.servletPath: ${pageContext.request.servletPath }<br/>
action name: ${com.opensymphony.xwork2.ActionContext.name }<br/>
action name 2: ${#context['struts.actionMapping'].name}<br/>

Unfortunately, here is what I am getting as output:

req.contextPath: /myContextRoot
req.requestURL: http://localhost:9080/myContextRoot/WEB-INF/app/layout/simpleLayout.jsp
pageContext.request.requestURL: http://localhost:9080/myContextRoot/WEB-INF/app/layout/simpleLayout.jsp
pageContext.request.requestURI: /myContextRoot/WEB-INF/app/layout/simpleLayout.jsp
pageContext.request.servletPath: /WEB-INF/app/layout/simpleLayout.jsp
action name:
action name 2: 

I am looking for a solution where I can achieve the following functionality:

<c:choose>
    <c:when test="${pageContext.request.requestURI == 'page1.action')}">
        <c:set var="page1ButtonClass" value="class=\"active\""/>
    </c:when>
</c:choose>

Just to provide some context, our setup involves Struts 2.3.8.

Answer №1

Give this code a shot

<c:set var="action" value="${#context['struts.actionMapping'].name}"/>
Action name: ${action}<br>

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

Which tools are best suited for Xamarin development?

Recently, I've been contemplating how to style my app. One common approach is using CSS, but the question that lingers in my mind is whether it's truly compatible and if I should begin utilizing CSS. Is there perhaps a different language that wou ...

Issue with border-color in CSS on Chrome tables

Here is a table style I have defined for selected elements: tr[selected] { background: #FFF; border-color: #000000; color: #000000; } To apply this style, I use JavaScript: $this.unbind().change(function () { element = $(this).parent ...

Checking a string to see if it contains just a single uppercase letter can be accomplished

Looking for the regex that ensures a given string contains only one uppercase letter, without allowing more than one to be matched. just 1 Uppercase character I understand the patterns for specific sets like [a-z], [A-Z], \d, and _|[^\w] (Am I ...

Explore the contents of the search results from a MYSQL query

Currently, I am developing a Java application that receives requests and saves them to a file for later retrieval. Recently, I decided to upgrade my application to utilize MySQL databases instead of plain text files. My objective is to query the database ...

Automating a comparison of data between an MS Excel file and an MS Access file with a custom script

Looking to automate a process involving an MS Excel file and an MS-Access file. The script needs to compare data from both files, identify rows with different values, and print out the contents. Wondering how to get started and what tools are required fo ...

The slider image on my Bootstrap website is not properly displaying on mobile devices

Check out my bootstrap website which features a slider: here Although the slider image is displaying correctly on desktops, it's not fitting properly on mobile devices. I've tried adjusting the CSS with the following code: @media only screen ...

Employing the queryForList function in the JdbcTemplate framework

Can someone assist me with using the query below? SELECT m.member_id, cardflag FROM member m, member_attribute ma WHERE m.member_number=:memberNumber AND m.ref_club_status IN ('A','S') AND m.member_id=ma.member_id The data type of mem ...

After incorporating an additional element, the li:nth-child(odd) selector is no longer functioning correctly

I previously had a setup where items in a list would have alternate colors using jQuery: $('ul.follows li:nth-child(odd)').addClass('alternate'); Everything was functioning properly until I introduced an a tag before the list items. N ...

An Iterative Approach to the Modified Fibonacci Series

As I was reviewing the iterative version of Fibonacci series algorithm, I came across this code snippet: int Fibonacci(int n) { int f1 = 0; int f2 = 1; int fn; for (int i = 2; i < n; i++) { fn = f1 + f2; f1 = f2; f2 = f ...

Tips for preventing an index out-of-bounds exception when working with ArrayLists

I've encountered an issue while trying to perform a substring operation on an ArrayList. When the list is empty, I receive an index out of bound exception. Below is the code snippet I am referring to: if(interviewTimingToFrom1.size()>0) { for ...

Breaking the lines in LESS

How can we instruct LESS to preserve line breaks in compiled CSS to enhance the cleanliness and readability of the code? Is there a way to configure LESS to maintain single-line CSS rules without adding line breaks between each selector, as shown in the e ...

Concealing an HTML form field until a dropdown selection is made

I have been struggling with my JavaScript code, searching for a solution to hide a form option (label and textbox) until a value is selected from a dropdown. Specifically, I want to hide the label and input box for "lookup" until a value is selected from t ...

Converting SQL queries to prepared statements in Java

Due to unavoidable circumstances (using code developed by a third party), we have found ourselves in need of converting SQL statements with inline values into prepared statements. Currently, we are relying on a flawed set of regular expressions that manage ...

Unable to execute the .java file

It seems like I'm having trouble with my homework. Every time I try to open the downloaded file, it appears unlike any normal class file. Even when I attempted to write a simple main method for testing purposes, I don't even see the option to run ...

Problem with the transform attribute in CSS

Having trouble rotating a div within another div. I tried using the transform property but it's not working as expected. I heard about another method which involves using :before pseudo-element, but I'm not sure what's wrong with that either ...

Running a New Scanner for Optimal Performance

Encountering an error code while attempting to initiate the scanner from the beginning. The functionality of this code is to ensure that the input does not exceed nine integers, if it does, then the output will be "Too many numbers". I'm currently wor ...

Utilizing background styles for enhancing the appearance of Ionic side menus

I've been experimenting with ionic and angular.js, trying to figure out the best way to apply background styles to side menus. I currently have a blurred background image with content boxes placed on top of it. My goal is to keep the background fixed ...

Layering effect for the jumbotron text with parallax scrolling

Trying to make the text in the jumbotron hide underneath the container when scrolling, but it's not working as expected. How can I get 'Main Title Goes Here', 'Subtitle' and the blue box to go under the lorem ipsum text? I tried se ...

Encountering a Spring POST 400 error in Postman when updating a class parameter from 2 to 1

Below is the code snippet from my @RestController class: @RequestMapping("api/") @RestController public class RecommendationsController { @PostMapping(path = "cart") public List<RecommendationDTO> getCartRecommendations(@NonNull @RequestBody Lis ...

The appearance of the page varies between Ubuntu and Windows 7 when viewed on Firefox 31

This situation is completely new to me: The page I designed appears differently on Firefox 31 in Ubuntu (correct): compared to Windows 7 (wrong): I was able to replicate this issue on another Windows 7 machine using FF 31. My HTML and CSS both validate w ...