spring fails to run javascript

In my project, I am utilizing Spring MVC 3 framework.

Below is the snippet of my AddressController:

@Controller
public class AddressController {
    private static Logger logger = Logger.getLogger(AddressController.class);

    @RequestMapping(value="/address",method=RequestMethod.GET)

    public ModelAndView init(
       @RequestParam(value="language",required=false,defaultValue="fr") String language){
               Locale locale = new Locale(language);
               logger.info("here");
               String[] isoCountries = locale.getISOCountries();

               Map<String,String> treeMap = new TreeMap<String,String>();

               for(String isoCountry : isoCountries){
                      Locale countryLoc = new Locale(language, isoCountry);
                      String name = countryLoc.getDisplayCountry(locale);

                      if(!"".equals(name)){
                             treeMap.put(name,name);
                      }
                }

                Map<String,String> tree = new TreeMap<String,String>(treeMap);
                ModelAndView modelAndView = new ModelAndView("address");
                modelAndView.addObject("address",new Address());
                modelAndView.addObject("countriesList", tree);

                return modelAndView;
    }
} 

Initially, when I access /address, it successfully reaches my controller and returns address.jsp which executes the JavaScript. However, when I try /address?language=fr or /address?language=en, the JavaScript code in my address.jsp does not get executed.

This section pertains to my address.jsp:

<%@page import="org.springframework.context.i18n.LocaleContextHolder"%>
 <%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
 <%@ taglib prefix="forms" uri="http://www.springframework.org/tags/form" %>
 <%@page import="com.application.myGoogleAppEngine.Internationale"%>
 <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
 <%@ page import="java.util.Locale" %> 
 <%@ page import="java.util.List" %> 
 <%@ page import="java.util.ArrayList" %> 
 <%@ page import="java.util.Collections" %> 
 <html>
 <head>
      <jsp:include page="ressources.jsp"></jsp:include>
      <link rel="stylesheet" type="text/css" href="stylesheets/320x480/portrait/address.css" />

      <%! Internationale internationale = Internationale.getInstance(); %>
      <script>
$(document).ready(function(){
     //checkParams();
     alert("here");
     var unit = "em";
     alert("here2");
     $("#backButton").attr("href","/index");

     $('#validationBtn').click(function(){

            var streetName = $('#streetName').val();
            var streetNumber = $('#streetNumber').val();
            var zipCode = $('#zipCode').val();
            var city = $('#city').val();
            var country = $('#country').val();

            var ref = "MyServlet?streetName="+streetName+"&streetNumber="+streetNumber+"&zipCode="+zipCode+"&city="+city+"&country="+country;

            $(this).attr("href",ref);

       });
     });

//rest of the script
</script>
<body>
  <a id="backButton" data-role="button" data-icon="arrow-l"
    data-ajax="false"> 
    <spring:message code="backButton"/>
</a></div>

 //rest of the code
</body>

Answer №1

Within the framework of web MVC, Spring operates as a server-side technology while Javascript functions on the client side (browser). This means that Spring is unable to directly execute Javascript code.

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

Determining the spatial capacity of a mesh using ThreeJS surpasses the volume of its bounding box

Issue at Hand: The challenge lies in the fact that the bounding box volume is turning out to be smaller than the volume calculated from the mesh. Attempts So Far: To begin with, I computed the volume of a bounding box using the following code: //loaded ...

Tips for creating responsive content within an iframe

I have inserted a player from a website that streams a channel using an iframe. While I have managed to make the iframe responsive, the video player inside the iframe does not adapt to changes in viewport size. Despite trying various solutions found online ...

Is there a need for a specialized Filter Chain for TestClasses?

Currently, I am utilizing spring-boot along with @WebIntegrationTest to conduct a series of Selenium tests. My main objective is to modify the filters for my test cases. After thoroughly reviewing the documentation, I have not yet discovered a method to a ...

Preview functionality is disabled in the iOS share extension

Currently, I'm developing a share extension for Safari on iOS. Our approach involves utilizing the default UI provided by iOS and extending the SLComposeServiceViewController class. In addition to this, I have incorporated a JavaScript function to ext ...

Node.js: Calculating the number of requests processed per second in the http.get()

In my node.js project, I am creating a simple application for sending HTTP requests. var http = require('http'); var options = { host: 'www.example.com', port: 80, path: '/index.html' }; for(var i = 0; i < 500; i++ ...

Sort and incorporate elements by multiple strings present in an array

Looking to filter and include strings in an array by matching them with items in another array? Here is a sample code snippet that filters based on a single string: const filteredString = `${this.filter}`.toLowerCase(); this.filteredCampaigns = this. ...

Sorting an array of floating point numbers in Java: How to arrange them in descending order?

When attempting to sort an array of floats in reverse order using the following code snippet, I encountered an error message. Can you help me identify the issue? float sortedData[]=new float[100]; ... Arrays.sort(sortedData,Collections.reverseOrder()); ...

Guide to using JavaScript to populate the dropdown list in ASP

On my aspx page, I have an ASP list box that I need to manually populate using external JavaScript. How can I access the list box in JavaScript without using jQuery? I am adding the JavaScript to the aspx page dynamically and not using any include or impor ...

Submitting data from a dropdown menu using Ajax in Struts 2: A step-by-step guide

I have a select tag with the s:select element inside a form. My goal is to send a post request to the specified action using Struts 2 json plugin. I do not have much knowledge in javascript or jquery. <s:form action="selectFileType" method="post" ...

Challenges arise when utilizing CSS3 animations in conjunction with transitions triggered by toggling a JavaScript class

Struggling to activate an animation while updating a class using JavaScript for a PhoneGap app. Planning on utilizing -webkit- prefixes for compatibility. However, the animations are currently unresponsive in Chrome during testing, both when applied to th ...

The Google Maps JavaScript API is displaying a map of China instead of the intended location

After multiple attempts, I am still facing an issue with setting up the Google Map on my website. Despite inputting different coordinates, it consistently shows a location in China instead of the intended one. Here is the code snippet that I have been usin ...

Implementing specific CSS styles for images that exceed a certain size limit

Currently, I am facing a dilemma as I work on developing a basic iPhone website that serves as a port for my blog. The main issue I am encountering is the need to add a border around images above a specific size and center them in order for the blog to hav ...

Exploring Event Propagation in AngularJS

Currently, I am working on developing a web application using angularjs for the first time. A key feature that I aim to introduce is the ability for users to create a div in the main window upon clicking on an image in the menu. To achieve this functional ...

Can we set a restriction on the maximum number of children a particular div can contain?

I'm trying to find a way to restrict the number of children in a div. The concept is that there is a selected commands div where you can drag and drop available commands (essentially buttons) from another div called available commands. However, I wan ...

Stop the annoying page flicker in Next.js 12 by implementing a custom dark mode using Tailwind CSS classes

Is there a way to prevent the page flash when implementing dark mode in Tailwind CSS using classes in Next.js v12 without relying on third-party packages like next-themes? I have explored different solutions: This StackOverflow Q&A How to fix dark mo ...

Optimizing normals for unindexed BufferGeometry in Three.js

Currently, I am attempting to refine the normals of a mesh starting from an non indexed BufferGeometry. A similar query has been addressed in the past, however, the Three.js API has undergone significant changes since then and I am unable to make it work o ...

Update the content of a div twice simultaneously

My AJAX call is currently working fine, but the response time is slow. To prevent users from clicking multiple times while waiting for a response, I want to display a message like "Converting please wait" before the data is received. Below is the code that ...

Woops! Looks like there's an issue - the property 'url' is not defined and cannot be

I am currently working on fetching data from a REST API using angular2, and everything seems to be going smoothly. However, I have encountered an error that only appears in the console when calling {{content.img.url}}. Interestingly, the code executes fine ...

Synchronizing Vuetify Carousel with dynamic route parameters

I'm facing an issue where the v-carousel value does not sync correctly with a route parameter using a computed property. Despite waiting for the mounted hook, the carousel seems to emit its own input and disregard the initial value from the route para ...

What is the best way to send multiple values along with an image when uploading to a server using AngularJS and NodeJS?

Client side: Having successfully implemented file upload functionality using AngularJS and NodeJS, I am facing an issue where I need to pass 'name' and 'email' parameters to the server along with the uploaded file. Server side: Once ...