Como eu faço pra jogar os dados do NewServlet.java para o mostradados.jsp? Logo abaixo tenho o meu index.jsp de onde pego os dados e jogo no Servlet:
<%--
Document : index
Created on : 23/01/2008, 09:01:11
Author : Moacir
--%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Arquivo.jsp</title>
</head>
<body>
<form action="NewServlet" method="post">
<center>
<h1>Digite nome e senha:</h1><p></p>
Nome: <input type="text" name="nome" value="" size="10" /><p></p>
Senha: <input type="password" name="senha" value="" size="10" /><p></p>
<input type="submit" name="botao" value="Logar" size="10"/>
</center>
</form>
</body>
</html>
esse é meu Servlet:
package Codigos;
import java.io.*;
import java.net.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class NewServlet extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
}//fim do get
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String nome = request.getParameter("nome");
String senha = request.getParameter("senha");
if(nome.equals("teste")&& senha.equals("123")){
response.sendRedirect("ok.html");
}
else if(nome.equals("a") && senha.equals("a")){
/*Aqui e que nao to sabendo como faco...*/
request.setAttribute(nome, "");
response.sendRedirect("mostradados.jsp");
}
else{
response.sendRedirect("erro.html");
}
}//fim do post
}//fim da classe
e tenho meu Jsp:
<%--
Document : mostradados
Created on : 23/01/2008, 10:27:59
Author : Moacir
--%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Mostra dados.jsp</title>
</head>
<body>
<%
String nome = request.getParameter("nome");
%>
<h2>Voce digitou esses dados: </h2><%=nome%>
</body>
</html>