简体   繁体   中英

How send across a parameter from a jsp page to a html page?

I can pass a parameter from .html to .jsp, but can't pass from .jsp to .html. What can be done to receive the parameter from .jsp? Would it be possible?

This is what we tried so far:

Javascript code on html:

    <script>
        function mensagemErro() {
            document.getElementById("mensagem").innerHTML = ${mensagem};
        }
    </script>

JSP code:

<html>
<head>
    <title>Login</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<% 
    ControleUsuario controleUsuario = new ControleUsuario();
    Usuario usuario = new Usuario();

    usuario.atualizarLogin(request.getParameter("login"));
    usuario.atualizarSenha(request.getParameter("senha"));

    if(controleUsuario.obterUsuarioLogin(usuario.obterLogin()) != null){
        if(controleUsuario.obterUsuarioLogin(usuario.obterLogin()).obterSenha().equals(usuario.obterSenha())) {
             request.setAttribute("mensagem", "Senha correta!"); 
        }else{
            request.setAttribute("mensagem", "Senha incorreta!");
        } 
    }else{
        request.setAttribute("mensagem", "Login não encontrado!");
    }
%>
<body>

</body>

You could use scriptlets , but you're better off using JSTL and the Expression Language (EL) in the JSP:

<label class="message">
    <c:if test="${not empty requestScope.mensagem}">
        ${requestScope.mensagem}
    </c:if>
</label>

If you still want to stick to scriptlets then you could do something like:

<label class="message">
    <% if(request.getAttribute("mensagem") != null) { %>
        <%= request.getAttribute("mensagem") %>
    <% } %>
</label>

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