简体   繁体   中英

spring doesn't execute javascript

I use Spring MVC 3 in my project.

This is 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;
    }
} 

The first time, when I executed /address, it's going well to my controller and it returns my address.jsp by executing the javascript in this last one. But when I execute /address?language=fr or /address?language=en, the javascript code of my address.jsp is not executed.

This is a part of 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>

In web MVC spring serves as server side technology. Javascript is client (browser) side technology, thus Spring "cannot" execute javascript.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM