逃避链接中的反斜杠

时间:2015-01-12 13:06:10

标签: javascript jsp

首先,对不起我的英语。

我试图做下一个,但我不能。

我有一个jsp,我从数据库中检索菜单选项的链接。我有一个Java变量,我存储链接,并将其分配给JavaScript变量

var link = '<%=link%>'

一切正常,外部链接指向其他网页,但当数据库中的链接类似于此"\\ctlmnas1\PlataformaEstadisticasWeb\DWH&BI\BI&DWH.htm"时,反斜杠会被转义并且链接构建错误。

这就是我在打开的窗口中构建链接的方式:

strHTMLderecha += "onClick='window.open(\"" + link + "\")'>";

在所有情况下都运行良好,但在链接具有此反斜杠"\"的情况下则不行。

我不知道如何解决它。你能帮帮我吗?

这是代码:

<%
try {
    sql="SELECT a.id_tab AS id, a.name AS nametab, is_visible AS visible, file_name AS filename, is_only_icon AS onlyicon, node_order AS node, link AS link, int_link AS intlink FROM nptab a, nptablink b WHERE a.id_tab = b.id_tab order by node ";
    rs = stm.executeQuery(sql);
    cnx.commit();
    while (rs.next()) {
        idTab = (String) rs.getString("id");
        nameTab = rs.getString("nametab") != null ? (String) rs.getString("nametab") : "";
        visible = rs.getString("visible") != null ? (String) rs.getString("visible") : "";
        fileName = rs.getString("filename") != null ? (String) rs.getString("filename") : "";
        onlyIcon = rs.getString("onlyicon") != null ? (String) rs.getString("onlyicon") : "";
        node = rs.getInt("node");
        link = rs.getString("link") != null ? (String) rs.getString("link") : "";
        intLink= rs.getString("intlink") != null ? (String) rs.getString("intlink") : "";
        // Si es visible se pinta
        if (visible != null && visible.equals("1")) {
%>
            MenuIdTab = '<%=idTab%>';
            MenuNameTab = '<%=nameTab%>';
            MenuIconTab = '<%=fileName%>';
            OnlyIconTab = '<%=onlyIcon %>';
            iNode = '<%=node%>';
            link = '<%=link%>';
            intLink = '<%=intLink%>';

            if(MenuIdTab == "") {
                strHTMLderecha += "<td id='td0' name='tdtab' class='dato1 w364' nowrap='yes' style='cursor: default'>";
                strHTMLderecha += MenuNameTab;
            } else {
                var img="../default/shared/skin/page/labo/css/header/img/"+MenuIdTab+".gif";
                strHTMLderecha += "<tr style='background-color:#f2f9e8'><td style='border-bottom: 1px solid #DAEDBF;' id='td0' name='tdtab' class='dato1 w364' nowrap='yes' valign='middle'";

                if (intLink != null && intLink == "1") {
                    strHTMLderecha += "onClick='window.location.href=\"" + DEFAULT_PAGE + "?idtab=" + MenuIdTab + "\"'>";
                } else {
                    strHTMLderecha += "onClick='window.open(\"" + link + "\")'>";
                }

                strHTMLderecha += "<img src='" + img + "'>&nbsp;&nbsp;";

                strHTMLderecha += "<span style='cursor:pointer;cursor:hand;padding-left:6px' >";

                if(MenuIconTab != "")
                {
                    strHTMLderecha += "<img align='absmiddle' vspace='2' hspace='2' src='"+MenuIconTab+"' alt='"+MenuNameTab+"'>" ; 
                    if(OnlyIconTab == "true")
                    {

                        strHTMLderecha += "</span>";
                    }
                    else
                    {
                        strHTMLderecha += MenuNameTab + "</span>";
                    }

                }
                else
                {
                    strHTMLderecha += MenuNameTab+"</span>";
                }
            }

<%          
        }
    }
%>
    document.write(strHTMLderecha);
<%
                                                } catch(SQLException esql) {
    System.out.println("ERROR OBTENIENDO LOS LINKS DE LAS PESTAÑAS" + esql.getMessage());
                                                }
%>

0 个答案:

没有答案