Handling userlogin in struts

Dear all
i want to know how to handle user login in struts.
when user logsin i create a variable in session (storing user name and email id in session as a object )
my file strutcure is
layouts
[contains layout for struts]
pages
[contains including files (combines layouts and tiles)]
tiles
[indivudual tiles of page]
where should i write my session checking ? and how to forware to login page.
please help me thanks you
archi

you could create yourself a custom tag
if the tag detects tha the user is not logged in it uses the response object of the page to forward to the login page

Similar Messages

  • How to handle checkbox in struts

    Hi,
    Can you help me how to handle checkbox in Struts?
    When i select/unselect checkbox in one page ,It should be selected/unselected stage when i come next time to that same page.

    Hi,
    Can you help me how to handle checkbox in Struts?
    When i select/unselect checkbox in one page ,It should be selected/unselected stage when i come next time to that same page.

  • How to handle exception in struts

    i am using global exception to pass to a page that shows an error message.
    I also want to pass the actual error message to that page is that possible
    through the struts config
    <global-exceptions>
    <!-- global exception handler -->
    <exception
    key="global.message"
    type="java.lang.Exception"
    path="Errors.jsp"/>
    </global-exceptions>

    i am using global exception to pass to a page that shows an error message.
    I also want to pass the actual error message to that page is that possible
    through the struts config
    <global-exceptions>
    <!-- global exception handler -->
    <exception
    key="global.message"
    type="java.lang.Exception"
    path="Errors.jsp"/>
    </global-exceptions>

  • Persisting the post data while handling errors in STRUTS

    hi,
    Let me explain my situation.
    I have an updation form.On click of the update button I am doing some validations in my Action class.In case of any error it will redirect back to the input page.
    Now comes my problem.As I have told you,my form is an updation form.So it contains field already set with some values,a bean.When the error ,redirects control back to the input page,the newly enterd data,which has errors is not displayed and instead the old bean contents are resetted.
    How to persist the newly entered data?
    Any suggestions will be helpful,
    thanks,
    vysh

    Hi David, could you help me to write this kind of routine? (Like ON-ERROR Oracle Forms)
    I have tryed to follow a lot of examples published in this forum, but none of then are working properly.
    In the URLs bellow you will see that a lot of people are looking for the same solution.
    Re: Catching ORA errors in Validations
    Error Trapping
    Error Handling
    Handling Oracle error messages
    Re: Catching Unique constraint error.??
    Re: how to get custom error mwssage
    Re: showing oracle error ID
    Thanks
    Nilton
    Message was edited by:
    Nilton Maganha

  • How to handle sessions in struts

    i have created a session. even after logout its not destroying the session.
    //here i am creating session object
    public ActionForward setupdate(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response) {
              ApplicationForm applicationForm = (ApplicationForm) form;
              String eid=applicationForm.getEid();
              HttpSession session = request.getSession(true);
              try {
                   PrintWriter out=response.getWriter();
                   if( applicationForm.getEid() != null && ! applicationForm.getEid().equals("") )
              session.setAttribute("User",applicationForm.getEid());
              System.out.println("you are logged in");
              out.println("you are logged in");
              } catch (IOException e) {
                   // TODO Auto-generated catch block
                   e.printStackTrace();
                        return mapping.findForward("update") ;
    //this my logout method
    public ActionForward logout(ActionMapping mapping,ActionForm form,
                   HttpServletRequest request,
                   HttpServletResponse response)
              { ApplicationForm applicationForm = (ApplicationForm) form;
              //PrintWriter out=response.getWriter();
              HttpSession session=request.getSession(false);
              try {
                   PrintWriter out=response.getWriter();
                   if(session == null)
                        out.println("FIRST YOU NEED TO LOGIN");
                        System.out.println("FIRST YOU NEED TO LOGIN");
                   else
                        out.println("THANKS FOR USING OUR APPLICATION!!!!");
                        System.out.println("THANKS FOR USING OUR APPLICATION!!!!");
                        out.println("id---->"+session.getId());
                        session.getAttribute("User");
                        session.invalidate();
              } catch (IOException e) {
                   e.printStackTrace();
              return mapping.findForward("logout");}
    please me help me out.
    saju

    You might want to check the API on that method again.
    public void setMaxInactiveInterval(int interval)
    Specifies the time, in seconds, between client requests before the servlet container will invalidate this session. A negative time indicates the session should never timeout.
    With regards to tracking who is logged on there are two issues.
    1 - tracking who is logged on
    - I would probably use a Map in application scope. Database table will also work. Its the same idea. When they log in, mark their presence. When they logout/expire then remove it.
    2 - responding to login/logout/expire events.
    - I would recommend using a HttpSessionBindingListener
    public class User implements HttpSessionBindingListener {
      String name;
      public User(String name){
        this.name = name;
      public void valueBound(HttpSessionBindingEvent event){
        // record login of this user
        if (userLoggedIn(this)){
          //user already logged in - throw an error and invalidate session
        else{
          // mark user as logged in.
      public void valueUnbound(HttpSessionBindingEvent event){
        // record logout of this user.
    }The code is invoked by the object being added/removed from a session.
    User user = new User("Bob");
    session.setAttribute("user", user);Cheers,
    evnafets

  • Struts exception handling - Exception handler

    Hi ,
    I need some help for struts exception handling . Global exception is working fine in my struts application . But I need to show the exception stack trace also in the screen whenever the exception occurs.I guess this can be achieved if we use a custom exception handler instead of struts default exception handler . Can anyone please provide me a sample code to deal with a custom ExceptionHandler class ?
    Thanks in advance...
    Regards,
    BG

    The struts provides org.apache.struts.action.ExceptionHandler class for creating the custom exception handlers. All the custom Exception Handlers should extend the ExceptionHandler class and override the execute() method.
    //An Example
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import org.apache.struts.action.ActionForm;
    import org.apache.struts.action.ActionForward;
    import org.apache.struts.action.ActionMapping;
    import org.apache.struts.action.ExceptionHandler;
    import org.apache.struts.config.ExceptionConfig;
    public class CustomExceptionHandler extends ExceptionHandler {
    public ActionForward execute(Exception exception, ExceptionConfig config, ActionMapping mapping, ActionForm formInstance,
    HttpServletRequest request, HttpServletResponse response) throws ServletException {
    try {
    // TODO CustomeCode
    System.out.println("Exception Handler for the specific error");
    }catch (Exception e) {
    return (super.execute(exception, config, mapping, formInstance, request, response));
    Struts-config.xml File
    <exception key="error.system" type="java.lang.RuntimeException"
    handler="com.visualbuilder.handler.CustomExceptionHandler" path="/index.jsp" />
    Note:- This will transfer the control to the index.jsp after calling the exception handler. In the struts-config.xml we are adding the global exception for RuntimeException. You can add any exception like the previous example to some actions only.
    I have taken this example from following link. You may visit it.
    http://www.visualbuilder.com/jsp/struts/tutorial/pageorder/38/
    I would like if you share knowledge with me.

  • Handling runtime Exceptions in tomcat / struts

    Hi, I'm trying to find a way to cleanly handle exceptions in struts/tomcat. I've read a number of suggestions in my struts book, but none seem to work.
    What I've done is created an instance within my action class that deliberatley creates a NullPointerException. I want to be able to display an errorPage at this point, but whatever I do I just get the same horrible HTTP Status 500 error.
    Can anyone give any advice with this please?

    Check out the org.apache.struts.action.ExceptionHandler class. Basically you extend this class, and override the execute method. In the struts config file you add this entry...
    <global-exceptions>
    <exception
    handler="the pathname of the class that extends ExceptionHandler"
    key="message properties entry"
    path="error page jsp"
    scope="request"
    type="type of Exception you want to catch (Throwable)"/>
    </global-exceptions>
    This basically acts as a "catch all" global exception handle.

  • Adf-Struts/JSP/BC4J- and setting date fields from jsp

    Hi,
    I'm working with the new ADF Frameworks (JDev 9.0.5.1) and ran into some questions regarding exception handling using BC4J, Struts and JSPs.
    I have a DATE column in database and an entity and VO with a datefield with type oracle.jbo.domain.Date.
    My JSP shows a textfield and the user should enter a valid date. Everything fine, until date is of wrong format or contains illegal characters...
    Problem:
    ADF tries to do a setAttribute on the datefield in VO row which expects a parameter with type oracle.jbo.domain.Date. When the user entered e.g. "NiceWeather" as date, I get an IIlegalArgumentException while converting to the correct Date format. This exception isn't thrown by bc4j as AttrValException and therefore my JSP renders a global error instead of a message directly behind the date field.
    I tried to validate the datefield in my DataForm and in my Action in the validateModelUpdates() method, but with no fitting solution.
    Any ideas how to validate a datefield with adf/struts/jsp/bc4j?
    Thanks for your help!
    Torsten.

    Torsen - In the first instance I'd recommed that you try and handle it declaritively using the Struts Validator Framework . See http://otn.oracle.com/products/jdev/howtos/10g/StrutsValidator/struts_validator_howto.html
    There is a section in there on how to use the validator with ADF databound pages and you can check the format the user enters via generated JavaScript.
    Also check out the matching sample project:
    http://otn.oracle.com/sample_code/products/jdev/10g/ADFandStrutsValidator.zip - this has a data field check on it as well

  • How to handle manipulated servlet mapping entries?

    I am building a struts based web application with action url-pattern set to "*.do". During the test, I could break the application by enter wrong action name or wrong extentions such as "*.doo" .
    The global application exception handler won't handle this since it treat it as an correct action and try to look up it .
    For example, if the correct action mapping url is "member.do". I can break it by change to "mem.do" or "member.doo".
    The error message i got is:
    type Status report
    message /member.doo
    description The requested resource (/member.doo) is not available.
    Thanks all for the help!
    ---------------------------

    Your web.xml file is where you configure which requests get handled by the struts framework.
      <!-- Standard Action Servlet Mapping -->
      <servlet-mapping>
        <servlet-name>action</servlet-name>
        <url-pattern>*.do</url-pattern>
      </servlet-mapping>This is where it says "anything ending with ".do" is handled by the struts action servlet.
    Is that what you mean maybe?
    BTW I don't think you should have to handle users typing in *.doo into the address bar. There have to be SOME limits.

  • Problem with Pop up windows and struts

    Hi
    I have problem in working with pop-up windows and struts.
    I have parent page which basically lists some data and has a button for adding new record. when I press that button a child windndow will be opened for data entry. The child window has submit button to save data.
    when I press the button for save, It will go to action class and saves it in a database and forwards a new page.
    but I do not want to forward any new page. If any exception is raised during database saving, a message should be showed in child window otherwise the child window should close and the parent window should get refreshed.
    Can any one write me how we can handle this in struts.
    Thanks in Advance,
    SR

    This has nothing to do with struts, you can do the same with some plain JavaScript. Do the following...
    1) On error, forward to a error page
    2) On success, forward to a temp.html page.
    The code in temp.html would be like this
    <html>
    <head><script>
    window.opener.reload();
    self.close();
    </script></head>
    <body>Closing...</body>
    </html>Cheers
    -P

  • Seeking solution in WLP for using MVC struts framework

    Hi,
    We would like to implement Struts like similar solution with Weblogic Portal Server.
    I would like to know the possibilities of bringing the Struts framework in WLP
    and I also would like to know the contraints in implementing the similar framework
    in existing WLP.
    Thanks in advance.
    Regds,
    Ratnakar

    Hi Rathnakar,
    In this very same newsgroup this subject has risen in september last year.
    I include the posting, but admit that I have not tried it so far.
    Regards,
    Ad van Ommen
    [email protected]
    ===================================================
    "Raphaël Faudou" <[email protected]> wrote in message
    news:<[email protected]>...
    I have not seen any official document on this integration but I personnaly
    developped
    a struts-portal adapter that allows a struts-based webapp to run as a
    portlet
    in the BEA portal.
    The idea is to redirect the displaying
    nstruction -requestDispatcher.forward(request,
    response) - toward the portal webflow servlet with the appropriate
    parameters
    (portletName, pageName, event).
    Remark : If you use struts 1.1, this adapter is very simple because you only
    have
    to inherit the RequestProcessor class and redefine the "doForward" method.
    Then, you have two design solutions :
    1) you model a simplified webflow with only presentation nodes and
    transitions
    that match what your navigation as specified in your struts-config.xml.
    In this case, logic is handled by Struts framework and presentation is
    handled
    by the portal webflow servlet.
    2) you dont' want to use portal webflow and you have to bypass it by
    developing
    another adapter at the portal side.
    In this case, logic and presentation are handled by th Struts framework and
    the
    portal adapter only displays the next page in the appropriate portlet.
    Conclusion : you can deploy a struts-based application in the BEA portal
    after
    developing one or two adapters that can be generic.
    Good luck
    =====================================================
    "Ratnakar Sonti" <[email protected]> wrote in message
    news:[email protected]...
    >
    Hi,
    We would like to implement Struts like similar solution with WeblogicPortal Server.
    I would like to know the possibilities of bringing the Struts framework inWLP
    and I also would like to know the contraints in implementing the similarframework
    in existing WLP.
    Thanks in advance.
    Regds,
    Ratnakar

  • Architecture question: Integrating AJAX and STRUTS

    I'm slowly growing in familiarity with STRUTS and I have the basics of AJAX down, certainly as far as the request-response-parse-do something useful with the data paradigm goes.
    My question is more about best practices in using an AJAX enable front-end with a STRUTS-based back-end.
    In a nutshell, each user action is handled by a STRUTS action subclass. Requests are picked up by the STRUTS front controller and passed on to the handler for processing. The handler is then able to tell the controller which jsp/resource to send back to the user.
    With AJAX, we are (generally) making specific data requests. We are essentially asking for data based on a set of parameters passed through on the request.
    In the case of a dynamic search table (containing no business logic), the AJAX request is simply asking for a set of results that match some parameters supplied in the criteria form.
    What should handle that data request?
    I was thinking about a specific "data-server" set of classes which STRUTS can pass AJAX requests to.
    NOTE: I'm thinking about this from the perspective of a new development, not tacking on to an existing application.
    Thoughts, anyone?

    So let me broaden the question slightly? What are the
    best practices for implementing an AJAX solution with
    STRUTS? I have looked around on the net but not found
    anything that constructive yet.
    Suggestions and/or pointers welcome.I have played around with AJAX just to understand how the technology works and how ajax can be integrated into a j2ee (or any other for that matter) web application. I havent worked on a project which has analyzed the best practises/pitfalls of ajax and implemented a solution.
    Having said that, here's my take -
    Ajax, as far as I know and have seen is a 'view' thinggy - enhanced user experience, lesser clicks, blah blah. The underlying XMLHttpRequest technology is just another way to hit the server with a request. And as I said before, once the server receieves a request, it really doesnt/shouldnt matter where and how the request originated from - it could a tunelled http request (as from an applet/swing app), a normal http request from a browser or a XMLHttpRequest (read ajax). The server validates incoming params if any and performs business logic.
    And here's when the similarity ends. The response (or the view) is entirely dependent on the 'requestor'. For browsers, the server would emit html, wap for cellphones, objects to a swing/applet program (possibly).
    The point I am trying to make is that this (the view part) is where you'll have to concentrate on tweaking (using the so called best practises) for ajax requests. For instance, there are a set of ajax tags already that you could reuse in your jsps which help developers build cool ajax enabled apps.
    (See http://ajaxtags.sourceforge.net/)
    There however are a few standard best practises for using ajax itself (and this is at a general ajax as a technology level) - see for example
    http://www-128.ibm.com/developerworks/library/j-ajax1/?ca=dgr-lnxw01Ajax
    ram.

  • Cache problem when coming back from external application

    Let's see if I can explain this properly. We have an application consisting of a left menu with books and pages. Each page consists of one Struts portlet. In one case we direct the user to an external mail application. This is handled by the Struts action class setting some fields (identifier and a url to return to when closing the external application). Our action class forwards to a jsp page like this (where url, SESSION_KEY and LINKBACK_URL are populated by the action class)
    <form action="${url}" name="myForm" METHOD="POST" TARGET="_top">     
    <INPUT TYPE="hidden" NAME="i_session" VALUE="<c:out value='${SESSION_KEY}'/>">
    <INPUT TYPE="hidden" NAME="linkback" VALUE="<c:out value='${LINKBACK_URL}'/>">
    </form>
    <script language="javascript">
         document.myForm.submit();
    </script>
    The external application opens up in the same window and when the user closes it you're linked back to our application through the LINKBACK_URL. Now, when I click in the left menu as I did from the start all I see is a blank page (if I click once again it displays correctly) and if I press F5 I'm logged into the external application again so it seems the jsp page with the form is cached. I can in a way understand that it does but I don't want that so are there any way to get rid of this behaviour?
    Best Regards
    Torbjorn

    >
    Edited by Holy at 03/24/2008 11:32 PM

  • (future-)abilities of JSF !!??  @  JSF-developers

    Hi!
    We've got a Struts-based WebClient. In the near future we need to decide, wether we'll use the struts-faces integration library or to drop struts completely and integrate client's functionality into JSF.
    Now my important question: What will JSF implement in future (compared to current struts-functionality)? eg:
    - will JSF be able to handle declarative exception handling?
    - will there be a plug-in mechanism like in struts?
    - what about sub-application ?
    - will JSF-event-handling, etc. be as powerfull as struts' action-mechanism?
    maybe i didnt read the spec. enough, but i didnt find anything related to mentioned questions
    thanks in advance

    Keep in mind that JavaServer Faces is a UI component framework, primarily focused on what is happening inside a single page. It is not (by itself) a web application framework -- at least not in a 1.0 time frame. Further answers and thoughts below:
    - will JSF be able to handle declarative exception
    handling?The Struts way of doing this (your Action.execute method actually throws an exception) is not supported today; however, you can set up something similar by using logical outcomes to indicate that an error occurred, and creating navigation rules to redirect to a particular output page.
    - will there be a plug-in mechanism like in struts?Servlet 2.3 (required minimum for JavaServer Faces) already provides ServletContextListener, which does the same thing as Struts plugins, so we don't need anything special for this in Faces.
    - what about sub-application ?JavaServer Faces does not have a concept of sub applications, since it is focused on single pages.
    - will JSF-event-handling, etc. be as powerfull as
    struts' action-mechanism?I would suggest that JavaServer Faces support for server side event handling is already more powerful than the Struts concept of actions, but you'd have to be more specific about what you'd want to accomplish in order to know if you agree.
    maybe i didnt read the spec. enough, but i didnt find
    anything related to mentioned questions
    thanks in advanceCraig

  • WLS 9.2 Console App Conflicts with Stuts2 App

    We are seeing the following error when starting up our Struts2 application on the Admin server.
              ERROR org.apache.beehive.netui.pageflow.internal.AdapterManager :
              ServletContainerAdapter manager not initialized correctly.
              The error seems to be happening as a result of the struts configuration setting which allows you to set a class to handle MulitPart Requests:
              struts.multipart.parser=mypackage.MyMultiPartRequest
              It appears that this error only occurs when the application is installed on the admin server. Our application is not utilizing Beehive. It appears though that the Weblogic Console is. I believe that the two are conflicting. When running our application on a managed server without the console app, we do not get the error.
              This is okay since our production and test environments are set up this way anyhow. However, our developers working locally by installing the app in the admin server rather than running an admin server and a managed server.
              Anyone seen this or know of a work around?

    Have you been able to fix this problem?
              Did you try prefer-web-inf-classes" in the
              weblogic.xml file?
              Unfortunately, I don't have any suggestions. I'm in the same quandry and looking for answers.

Maybe you are looking for

  • IPhoto version 9.6.1 - Restore photos in trash

    How can I restore photos in my trash that haven't been emptied?  The trash indicates I have 3000 photos, I can click on the trash and view the pics...but don't know how to retrieve them. Any assistance would be great... Thanks in advance for any help

  • Control over iPod Safari and YouTube content?

    I would like my pre-teen to be able to use Safari on his iPod Touch, but I do not want him to have unfiltered access to the Internet. The same is the case with YouTube. It would be great for him to watch the silly videos about Charlie the Unicorn goi

  • Adobe RAW Profiles not showing up

    I tried to install the new Beta camera profiles, but they wouldn't show up. I deleted all the folders in the profiles folder, and now the only profile that shows up is "Matrix". I've tried to re-install the profiles, but I can't seem to get them to w

  • SQL help, counting values

    I have 3 fields within a Table that I need to run a report on, they are phone fields, like: pl_home pl_cell pl_other some customers have no phone numbers in none of these fields, some might have 1, some 2, all 3. What is the best way to count these p

  • OWA not working in some Sharepoint 2013 sites... but not all?

    I have a SharePoint 2013 farm connected to Office Web Apps, with a number of sharepoint web applications(mostly legacy sites, created before my time here). I have created three new web apps and, when I try to preview documents using OWA (or, in fact,