Hi ,
Thanks a lot for your response.
I used encodeURL and encodeRedirectURL, but it is not working. the getAttribute gives null.
let me paste the sample code, for this scenario.
I dont think, there is problem in the code,bcoz, its working fine using resin.
using tomcat3.3.1 it gives null.
The session variable setting is thro. I used getAttribute() in the servlet class for
testing purpose,it gives right answer. but retreiving the same data thro jsps after sendRedirect(), its now working. Using getRequestDispatcher(),its working.
but it will not work on the entire session..
Expecting ur reply,
bye,
Murugan
<html>
<head>
<title>This is the login page</title>
</head>
<body>
<h1>This is the Login Page</h1>
<form name="frm" method="post" action="/servlet/NC_ValidateLogin">
Userid :
<input type="text" name="userid" >
Password:
<input type="password" name="password" >
<input type="Submit" name="submit" value="Submit">
<input type="Reset" name="reset" value="Clear">
</form>
</body>
</html>
-- Servlet class file --
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class NC_ValidateLogin extends HttpServlet {
public void init (ServletConfig config) throws ServletException {
super.init(config);
}
public void doGet (HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
doPost(req, res);
}
public void doPost (HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
String nom = "Toto";
String sUser = null;
String sPass = null;
if (req.getParameter("userid") != null)
sUser = req.getParameter("userid");
if (req.getParameter("password") != null)
sPass = req.getParameter("password");
HttpSession session = null;
try {
session = req.getSession(true);
session.setAttribute("LoginName", nom );
session.setAttribute("user",sUser);
session.setAttribute("pass",sPass);
//res.sendRedirect("/NetCAST/Home/JSPA.jsp");
//getServletConfig().getServletContext().getRequestDispatcher("/NetCAST/Home/JSPA.jsp").forward(req, res);
res.sendRedirect(res.encodeURL("/NetCAST/Home/JSPA.jsp"));
String strUser = (String)session.getAttribute("user");
System.out.println("****"+strUser);
} catch (Exception e) {
System.out.println("Pas cool !");
}
}
}
-----JSP Page ----
<%@ page import="java.util.*"%>
<% String nom = (String)session.getAttribute("LoginName"); %>
<% String user = (String)session.getAttribute("user"); %>
<% String pass = (String)session.getAttribute("pass"); %>
<HTML>
<HEAD><TITLE>Age ?</TITLE></HEAD>
<BODY>
<BR>
<BR>
What is your Name ?
<BR>
My name is Mr. <%= nom %>
<br>
My userid is <%= user %>
<br>
My password is <%= pass %>
</BODY>
</HTML>