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



我正在用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"要保存,使标签"名称";它的输入文本没有出现。顺便说一下,我用的是玻璃鱼。如果你能帮我这个忙,我会很感激的。:)

您可以在同一个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>
<%
}
%>