Pessoal,
To com um probleminha. Não sei se isso é possível fazer: Tenho um bean na minha jsp e seu scope é session. Tem como eu referenciá-lo no meu servlet?Pq como está, qdo chamo o metodo getLogin, aparece o valor nullo.
Abaixo coloco o codigo do meu jsp e servlet, respectivamente.
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%--
The taglib directive below imports the JSTL library. If you uncomment it,
you must also add the JSTL library to the project. The Add Library... action
on Libraries node in Projects view can be used to add the JSTL 1.1 library.
--%>
<%--
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
--%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<jsp:useBean id="adm" class="br.com.wwwt.ComponenteContabilidade.bd.beans.Administrador" scope="session"/>
<jsp:setProperty name="adm" property="login" param="login"/>
<jsp:setProperty name="adm" property="senha" param="senha"/>
<jsp:setProperty name="adm" property="status" param="status"/>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Manutencao do Administrador</title>
</head>
<body>
<form name="teste" method="POST" action="srvAdministrador">
<h1 ALIGN=CENTER>Administrador</h1><br>
<b>Login:</b> <input type="text" name="login" value=${login}> <br><br>
<b>Senha:</b> <input type="password" name="senha"> <br><br>
<b>Status:</b> <input type="radio" name="ativo" value="A" > Ativo
<input type="radio" name="inativo" value="I"> Inativo <br>
<br><br><input type="submit" name="inserir" value="Inserir">
<input type="submit" name="alterar" value="Alterar">
</form>
</body>
</html>
*
* srvAdministrador.java
*
* Created on 16 de Agosto de 2006, 17:16
*/
import java.io.*;
import java.net.*;
import javax.servlet.*;
import javax.servlet.http.*;
/**
*
* @author faccioli
* @version
*/
import br.com.wwwt.ComponenteContabilidade.bd.beans.Administrador;
public class srvAdministrador extends HttpServlet {
/** Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
* @param request servlet request
* @param response servlet response
*/
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
try{
HttpSession session = request.getSession(true);
Administrador admsrv;
admsrv = (Administrador) session.getAttribute("adm");
out.print(admsrv.getLogin());
}catch (Throwable e){
out.print("ocorreu um erro");
}
out.close();
}
// <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
/** Handles the HTTP <code>GET</code> method.
* @param request servlet request
* @param response servlet response
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
/** Handles the HTTP <code>POST</code> method.
* @param request servlet request
* @param response servlet response
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
/** Returns a short description of the servlet.
*/
public String getServletInfo() {
return "Short description";
}
// </editor-fold>
}