JSP之后,如何在HTML中加载值?

发布于 2025-02-07 05:59:42 字数 1726 浏览 0 评论 0原文

我正在使用JSP练习HTML,我一直在做一些练习以使其陷入困境,但是我不知道如何从JSP返回后加载价值。

我只有2页的代码,html和jsp

html:

        //var nombre = document.getElementById("nombre").value;
        function siexiste (){
            var nombre = document.getElementById("nombre").value;
            //alert(nombre);
            if (nombre === "") {
                document.getElementById("name").style.visibility  = "visible";
                document.getElementById("nombre").style.visibility  = "visible";
            }
            else{
                document.getElementById("name").style.visibility  = "hidden";
                document.getElementById("nombre").style.visibility  = "hidden";
            }
        }
    </script>
</head>
<body onload='siexiste()'>
    <form action="arttack.jsp">
        <label id="name" for="nombre"> Tu nombre </label>
        <input id="nombre" type="text" name="nombre" value=""/>
        <br> <br> <label> Color fondo </label> <br>
        <input id="fondo" type="text" name="fondo" value="" />
        <br> <label> Color fuente </label> <br>
        <input id="fuente" type="text" name="fuente" value=""/> <br> <br>
        <br>
        <input type="submit" value="Presiona" />
    </form>
</body>

以及JSP:

<body style="background-color:<%=fondo%>;">        
    <h1 style="color:<%=fuente%>"><%=n%> </h1>
</body>

全部有效,但是我想在JSP之后回到HTML,我需要保存“ nombre”的值,以便保存标签“标签”名称“及其输入文本不会出现。 顺便说一句,我正在使用玻璃鱼。 如果您能为我提供帮助,我将非常感谢。 :)

I'm practicing HTML with JSP, i've been doing some exercises to steep up, but i don't have a idea how to load a value after returning from a JSP.

i have only 2 pages of code, the HTML and JSP

HTML:

        //var nombre = document.getElementById("nombre").value;
        function siexiste (){
            var nombre = document.getElementById("nombre").value;
            //alert(nombre);
            if (nombre === "") {
                document.getElementById("name").style.visibility  = "visible";
                document.getElementById("nombre").style.visibility  = "visible";
            }
            else{
                document.getElementById("name").style.visibility  = "hidden";
                document.getElementById("nombre").style.visibility  = "hidden";
            }
        }
    </script>
</head>
<body onload='siexiste()'>
    <form action="arttack.jsp">
        <label id="name" for="nombre"> Tu nombre </label>
        <input id="nombre" type="text" name="nombre" value=""/>
        <br> <br> <label> Color fondo </label> <br>
        <input id="fondo" type="text" name="fondo" value="" />
        <br> <label> Color fuente </label> <br>
        <input id="fuente" type="text" name="fuente" value=""/> <br> <br>
        <br>
        <input type="submit" value="Presiona" />
    </form>
</body>

and the JSP:

<body style="background-color:<%=fondo%>;">        
    <h1 style="color:<%=fuente%>"><%=n%> </h1>
</body>

all works, but i want to come back to the HTML after JSP, and I need the value of "nombre" to be saved so that the label "name" and its input text don't appear.
I am using glassfish by the way.
If you could help me with this, I would really appreciate it. :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

太傻旳人生 2025-02-14 05:59:42

您可以将所有内容加载到同一JSP中。
因此,如果您没有加载值,则表格将显示。
如果您提交了该表格,它将隐藏起来和所示的值。

这样的事情:

 <%

    String nombre = "";
    String fondo = "";
    String fuente = "";

    if(request.getParameter("nombre")!=null){
        nombre = request.getParameter("nombre");
    }
    if(request.getParameter("fondo")!=null){
        fondo = request.getParameter("fondo");
    }
    if(request.getParameter("fuente")!=null){
        fuente = request.getParameter("fuente");
    }

    if(nombre.equals("")){
%>

    <body>
        <form action="#">
            <label id="name" for="nombre"> Tu nombre </label>
            <input id="nombre" type="text" name="nombre" value=""/>
            <br> <br> <label> Color fondo </label> <br>
            <input id="fondo" type="text" name="fondo" value="" />
            <br> <label> Color fuente </label> <br>
            <input id="fuente" type="text" name="fuente" value=""/> <br> <br>
            <br>
            <input type="submit" value="Presiona" />
        </form>
    </body>
<%
    }else{
%>

    <body style="background-color:<%=fondo%>;">        
        <h1 style="color:<%=fuente%>"><%=nombre%> </h1>
    </body>
<%
    }
%>

You can load everything in the same JSP.
So if you don't have a value loaded, the form is gonna show.
And if you have submitted that form, it's gonna hide and the values shown.

Something like this:

 <%

    String nombre = "";
    String fondo = "";
    String fuente = "";

    if(request.getParameter("nombre")!=null){
        nombre = request.getParameter("nombre");
    }
    if(request.getParameter("fondo")!=null){
        fondo = request.getParameter("fondo");
    }
    if(request.getParameter("fuente")!=null){
        fuente = request.getParameter("fuente");
    }

    if(nombre.equals("")){
%>

    <body>
        <form action="#">
            <label id="name" for="nombre"> Tu nombre </label>
            <input id="nombre" type="text" name="nombre" value=""/>
            <br> <br> <label> Color fondo </label> <br>
            <input id="fondo" type="text" name="fondo" value="" />
            <br> <label> Color fuente </label> <br>
            <input id="fuente" type="text" name="fuente" value=""/> <br> <br>
            <br>
            <input type="submit" value="Presiona" />
        </form>
    </body>
<%
    }else{
%>

    <body style="background-color:<%=fondo%>;">        
        <h1 style="color:<%=fuente%>"><%=nombre%> </h1>
    </body>
<%
    }
%>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文