-5

Can someone can explain me what this line do and.

<servlet-mapping>
    <servlet-name>jsp</servlet-name>
    <url-pattern>/javascript/generic/messages.js</url-pattern>
</servlet-mapping>

It is possible to do otherwise ?

i have error my jsp not compile with this line

If i comment this line:

<!--    <servlet-mapping> -->
<!--        <servlet-name>jsp</servlet-name> -->
<!--        <url-pattern>/javascript/generic/messages.js</url-pattern> -->
<!--    </servlet-mapping> -->

In my messages.js :

<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>

var tabMessages = new Array();

tabMessages['errors.invalid']='<bean:message key="errors.invalid" arg0="{0}" arg1="{1}" arg2="{2}" arg3="{3}" arg4="{4}" />';
tabMessages['errors.maxlength']='<bean:message key="errors.maxlength" arg0="{0}" arg1="{1}" arg2="{2}" arg3="{3}" arg4="{4}" />';
tabMessages['errors.minlength']='<bean:message key="errors.minlength" arg0="{0}" arg1="{1}" arg2="{2}" arg3="{3}" arg4="{4}" />';
tabMessages['errors.range']='<bean:message key="errors.range" arg0="{0}" arg1="{1}" arg2="{2}" arg3="{3}" arg4="{4}" />';
tabMessages['errors.required']='<bean:message key="errors.required" arg0="{0}" arg1="{1}" arg2="{2}" arg3="{3}" arg4="{4}" />';
tabMessages['errors.byte']='<bean:message key="errors.byte" arg0="{0}" arg1="{1}" arg2="{2}" arg3="{3}" arg4="{4}" />';
tabMessages['errors.date']='<bean:message key="errors.date" arg0="{0}" arg1="{1}" arg2="{2}" arg3="{3}" arg4="{4}" />';
tabMessages['errors.double']='<bean:message key="errors.double" arg0="{0}" arg1="{1}" arg2="{2}" arg3="{3}" arg4="{4}" />';
tabMessages['errors.float']='<bean:message key="errors.float" arg0="{0}" arg1="{1}" arg2="{2}" arg3="{3}" arg4="{4}" />';
tabMessages['errors.integer']='<bean:message key="errors.integer" arg0="{0}" arg1="{1}" arg2="{2}" arg3="{3}" arg4="{4}" />';
tabMessages['errors.long']='<bean:message key="errors.long" arg0="{0}" arg1="{1}" arg2="{2}" arg3="{3}" arg4="{4}" />';
tabMessages['errors.short']='<bean:message key="errors.short" arg0="{0}" arg1="{1}" arg2="{2}" arg3="{3}" arg4="{4}" />';
tabMessages['errors.creditcard']='<bean:message key="errors.creditcard" arg0="{0}" arg1="{1}" arg2="{2}" arg3="{3}" arg4="{4}" />';
tabMessages['errors.email']='<bean:message key="errors.email" arg0="{0}" arg1="{1}" arg2="{2}" arg3="{3}" arg4="{4}" />';
tabMessages['errors.numeric']='<bean:message key="errors.numeric" arg0="{0}" arg1="{1}" arg2="{2}" arg3="{3}" arg4="{4}" />';
tabMessages['errors.filetype']='<bean:message key="errors.filetype" arg0="{0}" arg1="{1}" arg2="{2}" arg3="{3}" arg4="{4}" />';
tabMessages['errors.accord.nonvalide']='<bean:message key="affichagePaa.erreur.accord.nonvalide" arg0="{0}" arg1="{1}" arg2="{2}" arg3="{3}" arg4="{4}" />';
tabMessages['errors.telephone']='<bean:message key="errors.telephone" arg0="{0}" arg1="{1}" arg2="{2}" arg3="{3}" arg4="{4}" />';
tabMessages['errors.incorrectYear']='<bean:message key="error.incorrectYear" arg0="{0}" arg1="{1}" arg2="{2}" arg3="{3}" arg4="{4}" />';


tabMessages['errors.dateCumulAnnuelDepassee']='<bean:message key="declaration.saisieCARealise.validationCumulAnnuel.possibleALaBonneDate.erreur" arg0="{0}" arg1="{1}" arg2="{2}" arg3="{3}" arg4="{4}" />';
tabMessages['errors.dateCumulAnnuelEnCours']='<bean:message key="declaration.saisieCARealise.validationCumulAnnuel.dateOK.erreur" arg0="{0}" arg1="{1}" arg2="{2}" arg3="{3}" arg4="{4}" />';
tabMessages['errors.dateCumulAnnuelNonAtteinte']='<bean:message key="declaration.saisieCARealise.validationCumulAnnuel.dateDepassee.erreur" arg0="{0}" arg1="{1}" arg2="{2}" arg3="{3}" arg4="{4}" />';
tabMessages['errors.cumulAnnuelDejaValide']='<bean:message key="declaration.saisieCARealise.validationCumulAnnuel.dej�Valider.erreur" arg0="{0}" arg1="{1}" arg2="{2}" arg3="{3}" arg4="{4}" />';

tabMessages['negociation.suppression.ristourne']='<bean:message key="negociation.suppression.ristourne" arg0="{0}" arg1="{1}" arg2="{2}" arg3="{3}" arg4="{4}" />';
tabMessages['changement.champApplication.ristourne']='<bean:message key="negociation.AjoutRistourne.changement.champApplication.ristourne" arg0="{0}" arg1="{1}" arg2="{2}" arg3="{3}" arg4="{4}" />';
tabMessages['matrice.suppression.familleaSuivre']='<bean:message key="matrice.suppression.familleaSuivre" arg0="{0}" arg1="{1}" arg2="{2}" arg3="{3}" arg4="{4}" />';

tabMessages['alerte.suppression.simple']='<bean:message key="alerte.suppression.simple" arg0="{0}" arg1="{1}" arg2="{2}" arg3="{3}" arg4="{4}" />';
tabMessages['alerte.suppression.complexe']='<bean:message key="alerte.suppression.complexe" arg0="{0}" arg1="{1}" arg2="{2}" arg3="{3}" arg4="{4}" />';

tabMessages['cumul.annuel.temporaire']='<bean:message key="cumul.annuel.temporaire" arg0="{0}" arg1="{1}" arg2="{2}" arg3="{3}" arg4="{4}" />';

tabMessages['calcul.retrocession.type.retrocession.differente']='<bean:message key="calcul.retrocession.type.retrocession.differente" arg0="{0}" arg1="{1}" arg2="{2}" arg3="{3}" arg4="{4}" />';

function getMessage(key, arg0, arg1, arg2, arg3, arg4) {
    var res = tabMessages[key];
    if (arg0 != undefined) {
        res = res.replace(/\{0\}/g, arg0);
    }
    if (arg1 != undefined) {
        res = res.replace(/\{1\}/g, arg1);
    }
    if (arg2 != undefined) {
        res = res.replace(/\{2\}/g, arg2);
    }
    if (arg3 != undefined) {
        res = res.replace(/\{3\}/g, arg3);
    }
    if (arg4 != undefined) {
        res = res.replace(/\{4\}/g, arg4);
    }
    return res;
}

Example of function in a js file:

function PilotageMDDForm_required() { 

    var nbColonnesMarques = indColMarque;
    var nbLignes = indLignes;
    var indexValidation = 0;
    for(var k = 0; k< nbLignes+1; k++){

        indicetableauTotalCol = 0;

        for(var i = 1; i < nbColonnesMarques-1; i++){

            for(var j = 0; j < MonTableauMarquesFamille[i]+1; j++){

                for(var l = 0; l < MonTableauFamilleType[j]+1; l++){

                    var type = document.getElementsByName("colMarquePilotage["+i+"].colFamillePilotage["+j+"].colTypePilotage["+l+"].lignePilotage["+k+"].type")[0].value;

                    if (type == "ATTERI") {

                        eval("this.a"+indexValidation+" = new Array( \"colMarquePilotage["+i+"].colFamillePilotage["+j+"].colTypePilotage["+l+"].lignePilotage["+k+"].texte\", \"" + getMessage('errors.required','Montant') + "\", new Function (\"varName\", \"this.min='0.00'; this.max='100.00'; return this[varName];\"));");
                        indexValidation++;
                    }
                }
            }       
        }
    }   

}

I have this error:

Uncaught ReferenceError: getMessage is not defined

@Roman C: I do like that .?

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic"%>
<%@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

<html:base ref="site" />

<html:html>
<head>
<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<tiles:useAttribute id="title" name="title" />
<title><bean:message key="${title}" /> - v<bean:message
        key="numero.version" /></title>
<link rel="stylesheet" type="text/css"
    href="<html:rewrite page="/css/commun.css"/>">
<link rel="stylesheet" type="text/css"
    href="<html:rewrite page="/css/tiptip/tipTip.css"/>">
<link rel="icon" type="image/png" href="images/icone.ico" />
<script type="text/javascript"
    src="<html:rewrite page="/javascript/generic/jquery-1.2.3.pack.js" />"></script>
<script type="text/javascript"
    src="<html:rewrite page="/javascript/jquery.hotkeys.js" />"></script>
<script type="text/javascript"
    src="<html:rewrite page="/javascript/commun.js" />"></script>
<%--        <script type="text/javascript" src="<html:rewrite page="/javascript/generic/messages.js" />" ></script> --%>
<jsp:include page="/javascript/generic/messages.jsp" />
<script type="text/javascript"
    src="<html:rewrite page="/javascript/tiptip/jquery.tipTip.js" />"></script>
</head>
<body>
    <tiles:insert attribute="content" flush="false" />
</body>
</html:html>
Roman C
  • 49,761
  • 33
  • 66
  • 176
Mercer
  • 9,736
  • 30
  • 105
  • 170

3 Answers3

1

Well, it maps js file to jsp. It's not good, since you need to write jsp tags in the js file and render them on the server side. But js files should be static and they served by another servlet or static content provider. If you think that js is a static file and it's not JSP that should be rendered on the server side, then you change the extension of the file messages.js to .jsp. Then you don't need to use such servlet mapping, but you need to include messages.jsp to render some javascript content from the server side. You can do it easily with jsp:include directive. But you need to add <script> tag inside messages.jsp to render a javascript.

messages.jsp :

<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>

<script>
var tabMessages = new Array();
...
</script>

in another jsp where you were loading messages.js use

<jsp:include page="messages.jsp"/> 
Community
  • 1
  • 1
Roman C
  • 49,761
  • 33
  • 66
  • 176
0

This line, as part of web.xml, defines a servlet mapping, or a relationship between a URL or URL pattern, and the servlet that will be handling it.

In this case, you are stating that requests to /javascript/generic/messages.js will be handled by a servlet called jsp (defined using a <servlet>...</servlet> block in web.xml). That is an odd servlet name though, since servlets and JSP pages are distinct ways to render a page with Java code.

nanofarad
  • 40,330
  • 4
  • 86
  • 117
  • 1
    @Mercer Can you do ***WHAT*** otherwise?! I've been trying to get an answer from you for the last 6 minutes and you still haven't clarified what your goal is, whatsoever. – nanofarad Feb 04 '16 at 22:46
0

The Servlet mapping is ONLY for calling a Servlet program if the request comes through that URL. Specifying other than Servlet class will not be appropriate. As know the Servlet program executes the business logic and redirects to the output through a JSP file.

Shaan
  • 588
  • 1
  • 4
  • 15