Bom pessoal, mais uma vez preciso de ajuda de quem entende!!
Como eu faço pra adicionar mais um página e redirecionar essa página? Aqui eu tenho um campo pra digitar nome e senha ai quando o usuário digitar os dados corretos, eu quero redirecionar para uma outra página, só que não to conseguindo colocá-la no arquivo.xml de configuração, ela fica como página de welcome-file
Esse é o código da página onde tem os campos…:
<html>
<head>
<title>Login e Senha</title>
</head>
<body>
<form action = "/NovoServlet" method="get">
Login = <input type="text" name="usuario" /><br />
Senha = <input type="password" name="senha" /><br />
<input type="submit" value="logar" />
</form>
</body>
</html>
Aqui é a outra página que quero redirecionar pra ela:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>JSP Page</title>
</head>
<body>
<form action = "NovoServlet?usuario=a&senha=a" method="get">
<h1>Teste</h1>
</form>
</body>
</html>
E esse é meu arquivo .jsp estou usando o método get:
public class NovoServlet extends HttpServlet {
public void destroy(){
super.destroy();
}
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
}
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=ISO-8859-1");
String usuario = request.getParameter("usuario");
String senha = request.getParameter("senha");
if(usuario.equals("a") && senha.equals("a")){
response.sendRedirect("teste.jsp");
}
}
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
}
public void init() throws ServletException {
super.init();
}
public String getServletInfo() {
return "Short description";
}
}
E finalmente meu arquivo.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<servlet>
<servlet-name>NovoServlet</servlet-name>
<jsp-file>/index.jsp</jsp-file>
</servlet>
<servlet-mapping>
<servlet-name>NovoServlet</servlet-name>
<url-pattern>/NovoServlet</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>teste.jsp</welcome-file>
</welcome-file-list>
</web-app>