Maintain session in JSP after using filters

I have to extend this application to maintain the session , because there are 10 jsp pages in my application.
When the user logs in , and hits a tab(which should redirect to another jsp page - assume users.jsp) the page is redirected back to the login page (instead of the users.jsp page) because of the filter.
How do I maintain the session here , so that a user who is logged in (with user name and password) could access the other pages instead of just being redirected back to the login.jsp page.
this is my filter page
package com.bea.genesis.tenantmgmt.utils;
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class FacesRedirectFilter implements Filter {
     public void doFilter(ServletRequest req,ServletResponse res,FilterChain chain)
     throws ServletException, IOException
          HttpServletRequest request = (HttpServletRequest)req;
          HttpServletResponse response = (HttpServletResponse)res;
          //String uri = request.getRequestURI();
          String relativePath = request.getServletPath();
          if ((relativePath.indexOf("/pages/") >= 0) && relativePath.endsWith(".jsf")) {
               //int length = uri.length();
               //String newAddress = uri.substring(0, length-3) + EXTENSION;
               //response.sendRedirect("login.jsf");
               RequestDispatcher rd = request.getRequestDispatcher("login.jsf");
               rd.forward(req, res);
          chain.doFilter(request, response);
     public void destroy() {
          // TODO Auto-generated method stub
     public void init(FilterConfig filterConfig) throws ServletException {
          // TODO Auto-generated method stub
Please reply
thanks

Thanks for the reply , How do I test in the filter whether the user is loged in or not.(I dont have clue , how to do tht)
this is my login Bean ---
import java.util.Map;
import javax.faces.context.FacesContext;
public class LoginBean extends AbstractBean {
     private String loginId;
     private String password;
     private LoginService loginService;
     private LoginValidator loginValidator = new LoginValidator();
     private TenantProfileService tenantProfileService;
     public String getLoginId() {
          return loginId;
     public void setLoginId(String _loginId) {
          loginId = _loginId;
     public String getPassword() {
          return password;
     public void setPassword(String _password) {
          password = _password;
     public LoginService getLoginService() {
          return loginService;
     public void setLoginService(LoginService loginService) {
          this.loginService = loginService;
     *public String login() {*
*          String authenticationStatus = GenesisConstants.RESULT_FAIL;*
*          appLogger.enterMethod(this, "login", loginId);*
*          if (loginValidator.validateData(this)) {*
*               try {*
*                    long profileId = loginService.authenticateUser(loginId,*
*                              password);*
*                    TenantProfileData tenantProfileData = retrieveTenantProfile(profileId);*
*                    if (tenantProfileData == null || !tenantProfileData.getStatus().equalsIgnoreCase(*
*                              GenesisConstants.TENANT_STATUS_ACTIVE))*
*                         throw new LoginException(*
*                                   "Tenant profile Not Active for the user.");*
*                    authenticationStatus = GenesisConstants.RESULT_SUCCESS;*
*               } catch (LoginException le) {*
*                    appLogger.error("Error in User Authentication", le.getMessage());*
loginValidator.addErrorMessage(null, le.getMessage());
*                    authenticationStatus = GenesisConstants.RESULT_FAIL;*
          appLogger.exitMethod(this, "login", loginId);
          return authenticationStatus;
     public TenantProfileData retrieveTenantProfile(long profileId) {
          appLogger.enterMethod(this, "viewTenant");
          FacesContext facesContext = FacesContext.getCurrentInstance();
          Map<String, Object> sessionMap = facesContext.getExternalContext()
                    .getSessionMap();
          appLogger.debug("profileId==", profileId + "");
          TenantProfileData tenantProfileData = new TenantProfileData();
          try {
               appLogger.debug("invoking TenantProfileService.getTenantById");
               tenantProfileData = tenantProfileService.getTenantById(profileId);
               appLogger
                         .debug("successfully completed TenantProfileService.getTenantById");
          } catch (TenantProfileServiceException te) {
               appLogger.debug("exception in TenantProfileService.getTenantById");
               throw new DataException(te.getMessage());
          sessionMap.put("tenantProfileData", tenantProfileData);          
          appLogger.exitMethod(this, "viewTenant");
          return tenantProfileData;
     public TenantProfileService getTenantProfileService() {
          return tenantProfileService;
     public void setTenantProfileService(
               TenantProfileService tenantProfileService) {
          this.tenantProfileService = tenantProfileService;
PLEASE HELP
THANKS

Similar Messages

  • Maintain session in JSP frame

    Hi,
    I am having trouble in maintaining session in jsp frames. -
    Here is sample code
    parent.jsp
    <HTML>
    <HEAD>
    <LINK rel=stylesheet type="text/css" href="defaults.css">
    <TITLE>abc</TITLE>
    <%     
         String checkAmount = "100.00";
         session.setAttribute("checkAmount", checkAmount);
         System.out.println("checkAmount in ppmain"+session.getAttribute("checkAmount"));
    %>
    <FRAMESET rows="235,*" frameborder="no" >     
    <FRAME NAME="pptop" SRC="top.jsp" frameborder=0 scrolling=no noresize >
    <FRAME NAME="ppbottom" SRC="bottom.jsp" frameborder=0 scrolling=no marginwidth=0 marginheight=0 noresize>
    </FRAMESET>
    </HTML>
    top.jsp -
    <HTML>
    <HEAD>
    <LINK rel=stylesheet type="text/css" href="defaults.css">
    <TITLE>top</TITLE>
    <%     
    System.out.println("session in top "+session);
    System.out.println("checkAmount in top "+session.getAttribute("checkAmount"));
    %>
    </HTML>
    It is not able to retain session in the top.jsp ( in SOP for session I get different session ID in parent.jsp and top.jsp
    This Works well in local but when gets deployed to WAS6 server troubles starts.
    Any help is appreciated.
    Thanks

    When you create URLs, you might want to try using JSTL to rewrite them:
    <FRAME NAME="pptop"
           SRC="<c:url value='top.jsp'/>"
           frameborder=0
           scrolling=no
           noresize >
    <FRAME NAME="ppbottom"
           SRC="<c:url value='bottom.jsp'/>"
           frameborder=0
           scrolling=no
           marginwidth=0
           marginheight=0
           noresize>Or you can use:
    SRC='<%= response.encodeURL("top.jsp") %>'

  • How to maintain session in jsp

    Hello Techies,
    I am very new jsp and doing xperimentation in jsp. I am having 3 jsp's namely a.jsp,b.jsp,c.jsp.
    In b.jsp I am having one combo box , after selecting the combo box I want to put the value in session.
    How can I do this one.
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <%@ page language="java" contentType="text/html; charset=iso-8859-1" %>
    <html>
    <head>
      <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
      <title>Untitled Document</title>
       <script language="javascript">
           function ll() {
                   alert("test");
    //            var sel=document.forms[0].rule;
                       document.forms[0].submit();
                   alert("form is submitted")
          </script>
    </head>
    <body>
    <select  name="comboBox" size="1" onchange="ll()">
         <option value="">1</option>
         <option value="">2</option>
         <option value="">3</option>
    </select>
    </body>
    </html>How can I set the selected value in this combo box into session.
    Can u guys help me out in fixing this problem.

    Well you have to submit the form first.
    In the java code:
    String comboValue = request.getParameter("comboBox");
    session.setAttribute("comboValue", comboValue);

  • Session-scope variable for JSP page used in a frame

    Hi,
    I don't know if there's a way to do this at the same time:
    (1)- assign session scope to a variable (in order to be able to retrieve recurrently the previous value each time the JSP is called);
    (2)- set its visibility in a way that it could be accessed only by the page that defines it. The JSP is used in a frameset along with an other JSP that can potentially define identical session-scoped variable (You understand why I want to keep them separate)
    session.setAttribute():
    seems not to be the thing I need
    pageContext.setAttribute():
    with SESSION_SCOPE, it behaves the same way as session.setAttribute(). with PAGE_SCOPE, condition (1) can't be satisfied.
    Does anybody have an idea ?
    Thanx in advance.

    I can see that you will not want to maintain two different files for every possible page on the site!
    It may be possible to do something like <frameset rows="*" cols="50%,*">
      <frame name="content1" src="file.jsp?frame=one" >
      <frame name="content2" src="file.jsp?frame=two" >
    </frameset>and then in the jsp<%
    String frame=request.getParameter("frame");
    session.setAttribute(frame+"AttributeName",attributeValue);
    %>This will set up two session attributes - "oneAttributeName" and "twoAttributeName". Depending on how many variables you have, this may prove just as difficult to maintain.
    You may end up having to simply pass url parameters between pages to maintain state within the individual frames, which is far from elegant also.
    I am interested in how you end up solving this one.

  • What is the use of session in jsp

    hai,
    what is the use of session in jsp. i cant understand from books. give some practical approach
    thanks

    give some practical approachYou sound like a supervisor ordering for a cup of coffee.
    I DONT TAKE ORDERS !!
    IMAO
    Which book did you refer ? Did you google ?

  • How to make a Struts message null after used in JSP?

    Hi,
    In the context of Struts/JSP,
    An action class might write error messages by
    ActionError msg = new ActionError("msg.request.something");
    ActionErrors msgs = new ActionErrors();
    msgs.add(ActionErrors.GLOBAL_ERROR,msg);
    saveErrors(request,msgs);
    This message will produce a popup modal window by the following JSP code:
    <logic:messagesPresent>
    <html:messages id="error">
    <!--<li class="infomsg"><bean:write name="error"/></li> -->
    <script>javascript:alert('<%=error%>')</script>
    </html:messages>
    </logic:messagesPresent>
    The problem is that this JSP page is shared by serveral actions: when another action invoke this page again, the previous error message will take effect again.
    So my question is how to make message null after used once by its author.
    Thx.
    PY

    msgs = null;

  • Session Timout JSP Page Forward

    Hi All,
    I am currently working on a JSP site and want to add a JSP page forward that takes place when the user's session times out after a period of inactivity.
    I have created a servlet that implements HttpSessionBindingListener and has methods in place for valueBound and valueUnboud. The methods are getting called as they should, however because there isn't an HttpResponse object I cannot do a response.forward....
    So my question: Is the HttpSessionBindingListener the correct interface to be implementing to accomplish my goal? If so, how do I forward the user to the login page? If not, what should I use and how do I forward the user to the login page?
    Thanks for your time and help.
    Aaron

    valueUnbound method? Arent you using a Model
    View Controller type architecture? The servlet
    is mainly used to to handle logic and navigate
    to the appropriate view(your java server pages).
    The code I supplied should be placed in the service
    method of your servlet.. then it can handle the
    request and determine where to go from there. Your
    servlet should have three methods, the doPost, the
    doGet, and the service method. The doPost and Get
    should pass the request and response objects on to
    the service method. Any other logic should be handled
    in other classes that you create. The service method
    basically decides what the next page should be.
    Hope this helps..

  • Session in JSP

    Hi all,
    I used session in my JSP pages. Now when user click Logoff link the page goes to a JSP page and there i invoked
    session.invalidate();to end the session.
    On that page there is a link to login again.
    If the user use that and then login with a different ID and store some info in database it still shows previous users ID meaning that session is still getting old value although i invalidated it.
    Can anyone please help me.

    Hi CodeYoda,
    Thanks for reply. I tried your code but still it doesn't work.
    Now let me explain the situation, When i turned the machine this morning and started tomcat and run my application with a different ID, and i did some updates in database and it still shows the ID that i used when i created the session couple of weeks back.
    Now i think this is a serious matter because it remembrs that ID only.
    Now let me clear the concept again. my jsp pages are not linked by data transfer but they have links of all pages on the menu in every page so when they login and in the second page i stored the login name in session after that i used it in a page which has no connection with any other pages. Now what i did is i made the page available for session and then i used the login name.
    Now is that mean that the login name is stored in that pageforever and since it doesn't send anything to logoff page and when we kill the session inlogoff page it is only killed in logoff page. That's my assumption. Can you please confirm me.
    Thanks

  • Closing/ending a session in jsp

    Hi guys i need help ending my session. I am using session just for parameter passing, my webpages doesnt need login logout function.
    These are my basic code:
    page1.jsp
    <%
    String prodlinesel = request.getParameter("prod_line");
    session.setAttribute( "sessprodline", prodlinesel );
    %>
    page2.jsp
    <%= session.getAttribute("sessprodline") %>
    how,when &where do i end my session ? thanks so much

    You can use session.removeAttribute("sessprodline");
    Calling session.invalidate() will invalidate the session.
    Otherwise it disappears after it times out - normally after about 30 minutes of inactivity from that session.

  • Regarding maintaining session in flex

    Hello,
              I am developing a flex application which is using jsp for database connectivity. I am using HTTP request for connecting to jsp page and passing and retrieving parameters. Now I wanted to ask how can I maintain session in flex so that I can know which client has logged into the system and on the basis of that can assign privileges to the client. Is it possible in flex and how?Reply needed urgently.
    Thanks in advance.

    Hi a.bhavika,
    There is not specifically any session management in Flex as it runs everything on the client side if at all you want to mainatain you can maintain it on the server side. ...and I think for your case I dont think you need any session managemenet as at the time of login only you can identify which user has logged in to the syetem and based on the user logged in you can load all the previleges of that particular user in the Flex application.
    Check out the links below for your understanding...
    http://www.forta.com/blog/index.cfm/2006/9/24/flex-and-session-state-management
    http://www.assembla.com/wiki/show/romoz/Session_Management_in_Flex
    Thanks,
    Bhasker

  • Maintaining Sessions through Multiple Servlets and Contexts

    Hi,
    I have a webapplication that works like this:
    * User connects to a login servlet on HTTPS
    * Users information is authenticated on HTTPS
    * An object is stored in the session for other servlets to validate the users access
    * Authenticated users are forwarded to an HTTP page where the session is used to make sure they were granted access
    My problem is this....Since I create the session in an HTTPS context, when I am in the HTTP context, I am unable to access the session and constantly get NULL. Is there any way that I can access the session from an HTTP context?

    What you can do is, just login using HTTPS and switch over to HTTP
    and then store data in session.That is true, but what I want in the session is basically a flag on whether or not the user was granted access. I would much rather set all that up on the secure line, and then just access it from the unsecure ones...
    For example, you are creating session using the
    http://testdev:port/index.jsp page.
    If access the same page(with hostname)
    http://10.300.20.18:8080/index.jsp, you can't get the session even
    though both are same web server and same web application. Because the
    browser treats it different sessionI think if you use my above solution with the explicit passing of the jsessionid, you can move from one domain to another and still maintain session. Not positive on that though...

  • Cisco ace Load balancer not maintaining session persistence

    Hi All,
    We have observed from the IIS logs on the internal webservers that loadbalancer is not maintaining session persistence for two specific request for the internal servers.
    https://123.xyz.com/Webresource.axd
    https://123.xyz.com/ScriptResource.axd
    Error
    Webresource.axd : 500
    Scriptresource.axd: 404
    Session persistence is maintained for all other requests hitting loadbalancer.
    Issue is observerd on hits for these two specified components. WebResource.axd and ScriptResource.axd are Http Handlers used by ASP.NET and Ajax to add client-side scripting to the outgoing web page.
    For e.g /WebResource.axd d=t2GXfySdqWmJ-lZSI0KVbw2&t=634868473645172160 is valid for server 1 and return 200 response but the same request is seen on few other servers where the response is 404 even though load balancer cookie is same. This means that if the request for the both the axd contains a valid decrypter and it connects to the right server then the response seen is 200.
    The url passed by the user contains d and t parameters when are unique for each user session.
    Solution tried:
    Accessed website via another VIP without http redirect rule but could not see difference.
    Tried to match machine key across all servers : Failed . Could see the ‘d’ value different for each server.
    Load balancer VIP :
    x.x.x.x
    redirect: http > https
    SSL Offload : ON
    Poool:
    WEB1
    WEB2
    WEB3
    WEB4
    WEB5
    All servers listening on port 80
    sticky config:
    sticky ihttp-cookie cookie1 vip-1.1.1.1-80-stickyfarm
      cookie insert browser-expire
      replicate sticky
      serverfarm vip-1.1.1.1_80
    sticky http-cookie cookie1 vip-farm:1.1.1.1:443
      cookie insert browser-expire
      replicate sticky
      serverfarm farm:1.1.1.1:443
    Has anyone else come across similar issue?
    Can you plese check if there is any config on cisco ace that will ensure that session persistence is maintained for these 2 requests.
    Thank you for all the help.
    regards,
    Sangram

    Hello Sangram,
    We would need simultanous packet traces before and after the ACE to get to the root cause of this issue so I would recommend that you open a cisco tac case for more in depth troubleshooing of this issue.
    Joel Lamousnery
    CCIE R&S - 36768
    Engineer, Customer Support
    Technical Services

  • How to maintain Session between two ear files?

    HI Guys
    I have deployed two ear files in oc4j. One is used to open applet and other for business operations.
    My problem is after calling applet my session gets invalidate. How to save session between two context
    I am new in this field please help!!
    the sooner the better
    Rahul

    Can I do this if I integrate oc4j with apache!!
    Can I maintain session
    Plz. Help
    Rahul

  • Maintaining sessions with a java bean

    I am trying to debug a Web App that occasionally loses its session when one
              page is being jsp_forwarded to another. The original JSP coder uses a Java
              bean named Session to hold all the sesssion information. The usebean tag is
              used to maintain the correct instance. This session loss did not occur when
              we were still running 5.1. Now with 6.1 we have this mysterious problem. Can
              anyone make suggestions on how to tackle this problem?
              The weblogic.xml file contains the working directory and the keepgenerated
              set to true. All else is default.
              Kenny
              

    Try the following forum (about JSP technology)
    http://forum.java.sun.com/forum.jspa?forumID=45

  • Insert data into table from JSP page using Entity Beans(EJB 3.0)

    I want to insert data into a database table from JSP page using Entity Beans(EJB 3.0).
    1. I have a table 'FRIENDS', (in Oracle 10g database).
    2. It has two columns, 'NAME' and 'CITY'. Both have datatype strings(varchar2).
    3. Now from a JSP page, having two textfields, 'NAME' and 'CITY', I want to insert data into table 'FRIENDS'.
    4. In between JSP and database is a Entity Bean(EJB 3.0) and a stateless session bean.
    5. I am using JDev as editor.
    Please provide me code ASAP or link with similar example.
    Thank you.
    Anurag

    Hi,
    I am also trying that scenario. So u can
    Post the jsp form data to a Servlet which will act as a Controller.
    In the servlet invoke the business method.
    Similar kind of app is in www.roseindia.net
    Hope this would help u.
    Meanwhile if u get any optimal solution, pls post it.
    Thanks,
    Happy Java Coding.

Maybe you are looking for

  • Application was unable to load database

    I have a RoboHelp 9 project that I left open on my computer overnight and microsoft updates ran causing my computer to restart.  When I try to open my RoboHelp 9 project, i get the following error: Open project was cancelled or the application was un

  • Browser slow-down with Linux Flash Player 9.0.21.78

    With more than one Flash animation/app playing, Firefox and all Gecko-based browsers (like Galeon) will grind to a halt. CPU load doesn't rise, however. The rest of the system is unaffected, only the browser seems to be running on a 16MHz 286... If I

  • Send e-mail after change document status solar02

    Hi... How is possible to send an e-mail for someone or a group, when a especific document status is changed to a new value? Thanks in advance, Warlei Figueiredo

  • Trouble open pdf files.  saying damaged files

    Recently PDF files that I can open and view from online will not open once saved to documents folder.  I get a message that says that the file is damaged.  I have reinstalled adobe reader and ran system update. 

  • Drop problem

    Hi all, I'm trying to drop html contents to Word and OpenOffice. Its works fine with word but not at all with OpenOffice. Is somebody can explain whats happen ? I also tried to drop using DataFlavor like :      new DataFlavor("text/html;class=java.la