Results 1 to 8 of 8
  1. #1
    abhivinay is offline Member
    Join Date
    Sep 2012
    Posts
    1
    Rep Power
    0

    Default Java servlet - redirecting url

    hi , can anyone help me !

    I am java beginner ( very new).

    I have website http://mywebsite.com ( my html site) and java webpages in http://mywebsite.com/app/index.jsp ( which is my login page)

    when I login with user credintials i can see logout (http://mywebsite.com/app/Logout.do) option on right corner when i click on it it is redirecting to again login page . i found that /apps/WEB_INF/LogoutAction class is responsible for this redirection .

    Now i want to change the code to redirect it to my html homepage http://mywebsite.com after clicking on logout

    LogoutAction.java file is below , please suggest me the appropriate changes for this .




    package logout;

    import javax.servlet.http.*;
    import org.apache.struts.action.*;

    public class LogoutAction extends Action
    {

    public LogoutAction()
    {
    }

    public ActionForward execute(ActionMapping p_mapping, ActionForm p_form, HttpServletRequest p_request, HttpServletResponse p_response)
    {
    String target = "login";
    p_request.getSession(true).invalidate();
    return p_mapping.findForward(target);
    }
    }


    Thank you

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

    Default Re: Java servlet - redirecting url

    That "login" target will be mapped in the struts xml for the LogoutAction showing where to go.
    Change that.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,642
    Rep Power
    7

    Default Re: Java servlet - redirecting url


  4. #4
    gowthamgutha is offline Member
    Join Date
    Sep 2012
    Location
    Guntur, India
    Posts
    27
    Rep Power
    0

    Default Re: Java servlet - redirecting url

    You can use
    // Throws IOException
    try
    {
    response.sendRedirect("http://mywebsite.com/app/index.jsp");
    }catch(Exception e){}
    [Moderator edit: link removed]
    Last edited by DarrylBurke; 10-04-2012 at 03:41 PM. Reason: Removed spammy link

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

    Default Re: Java servlet - redirecting url

    Which would beg the question of why use Struts.
    In other words, not a good answer.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  6. #6
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,193
    Rep Power
    19

    Default Re: Java servlet - redirecting url

    Quote Originally Posted by Tolls View Post
    not a good answer.
    Blog spam rarely is.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  7. #7
    gowthamgutha is offline Member
    Join Date
    Sep 2012
    Location
    Guntur, India
    Posts
    27
    Rep Power
    0

    Default Re: Java servlet - redirecting url

    You can set index.jsp in <welcome-file-list> in web.xml after everything.

    <welcome-file-list>
    http://mywebsite.com/app/index.jsp
    </welcome-file-list>

  8. #8
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

    Default Re: Java servlet - redirecting url

    Do you actually know Struts?
    I think not...

    Pleae don't answer unless you know the answer, instead of just guesswork.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Redirecting OutputStream to JTextArea
    By mellowcandle in forum AWT / Swing
    Replies: 0
    Last Post: 05-12-2011, 10:48 AM
  2. Redirecting Cases in a switch
    By rizowski in forum New To Java
    Replies: 7
    Last Post: 03-17-2011, 10:09 AM
  3. Redirecting output of java program to file
    By dewitrydan in forum New To Java
    Replies: 4
    Last Post: 11-17-2010, 06:58 AM
  4. Problem while redirecting script output to a file using java
    By umapathy_sekar in forum Advanced Java
    Replies: 4
    Last Post: 11-09-2010, 09:33 AM
  5. Need help in redirecting to a url
    By umapathy_sekar in forum Advanced Java
    Replies: 1
    Last Post: 09-27-2010, 12:52 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •