Servlet Redirecting

Does response.sendRedirect(url) method result in a permanent or a temporary redirect? Please elaborate.

Sounds like a homework question. I recommend that you view/download the servlet (and JSP) specs and you'll be able to easily find answers to questions like this.
http://jcp.org/aboutJava/communityprocess/first/jsr053/index.html

Similar Messages

  • Web.xml servlet redirection question

    Hi everyone;
    As you know web.xml file allows you to enter something like this
         <servlet-mapping>
              <servlet-name>application1</servlet-name>
              <url-pattern>/application1</url-pattern>
         </servlet-mapping>
    so you can find your application.
    As you know it is case sensitive so if a user enters /Application1 it wouldn't be found. I was wondering if i could put a node in there that would redirect requests from Application1 to application.
    Any ideas ?
    Stev

    oh i wasn't aware that i could put multiple nodes in there like this
    <servlet-mapping>
    <servlet-name>application1</servlet-name>
    <url-pattern>/application1</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
    <servlet-name>application1</servlet-name>
    <url-pattern>/Application1</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
    <servlet-name>application1</servlet-name>
    <url-pattern>/APplication1</url-pattern>
    </servlet-mapping>
    is there a way to simply make this case insensitive and all requests get translated to the lowercase versioN?
    Stev

  • Servlet redirection

    How do I send a redirect to a target frame in an html page, instead of the current frame using a servlet or JSP?

    Is there away to accomplish this without javascript; instead using a HttpServletResponse object to redirect to a target frame?

  • Servlet redirection but maintain url in browser (make sense?!?)

    Hi,
    Would like to have a url like www.foo.com/careers
    which will call a Servlet, passing in a parameter of "careers" so I know what content to display.
    But instead of the url changing to www.foo.com/Servlet?page=careers in the browser (due to obj.con redirect), is there a way I can do this without the url changing from www.foo.com/careers, but still calls the relevant servlet and passes in the correct parameter?
    Thanks

    We were covering a very similar topic in this thread:
    http://forum.java.sun.com/thread.jspa?threadID=5194280&tstart=10
    Ultimately you would use the If structure with regular expressions to restart the request internally (the user-agent does not see this) with the full URI. Something like:
    <If $uri =~ "/(.*)"
    and $uri !~ "^/Servlet.*" >
    NameTrans fn="restart" uri="/Servlet?page=$1"
    </If>
    This block appropriately placed in your obj.conf will internally restart the request with the original URI now used as the query string of the new request.
    You could also use this instead:
    <If not $internal
    and $uri =~ "/(.*)" >
    This will only perform the restart if the request being processed is determined to NOT be internally generated (e.g. an already restarted request).
    Of course you should make sure that you application generates URLs that are appropriate to this URI space, not the canonical URI space. This configuration will also be pretty greedy with your URI space, preferring to rewrite everything:
    /foobar/sub/dir/image.jpg
    becomes
    /Servlet?foobar/sub/dir/image.jpg
    So you'll want to refine what options you're willing to match, and restrict the expression used here to be less inclusive.
    For more information on this very nifty feature, see the docs at:
    http://docs.sun.com/app/docs/doc/820-1062/6ncoqnpfh?a=view

  • Servlet redirecting at Server side

    Hi,
    I need to redirect to a Servlet on another Servlet.
    response.sendRedirect("http://www.xyz.com/servlet/customerserviceServlet.TestServlet.do");
    I need to pass some request parameter. I know one method is to pass the parameter through the URL.
    However due to some security constraints I cannot use this method.
    Is there an alternate approach to this? Can I send the parameters using Header. If yes, then how?
    Thanks!!

    You cannot. Besides, being able to modify the header is just as big a security risk as sending the parameters as part of the url. Any idiot can install a packet sniffer and see what is inside the header. Perhaps encrypting the parameters is better?

  • Applet - Servlet - Redirection

    Hi all!
    I've got a problem that makes my hair stand up on my head..
    I'm working on a project of a web application based on struts.
    Two parts of this application are to complicated to be done in struts technology. So, I've to do it with java swing applets.
    I've made an applet that uses a servlet to get some data from the server, and that uses this servlet to save some data onto the server.
    It works fine, but now, I've to quit the current page (that displays the applet) and be redirected on another one.
    I've tried to call the servlet and do response.sendRedirect(URL) but i've got a security error..
    Is there any solution? Or must I put a button on the web page to do this?
    Thanks in advance for your attention..

    if it's redirecting to another server, then the applet needs to be signed.
    Note that URLConnection doesn't handle redirections for you. I think HttpURLConnection does, if you set some option for it (and of course, if URL.openConnect() reutrns an HttpURLConnection object for HTTP URLs)... check the API docs.

  • Servlet Redirection issue

    Hi,
    We have an web Application which uploads and Parses Excel File and redirects to an 1.jsp Page. We are facing an issue in redirection after Parsing Large Excel file greater than 15 MB, Tomcat is not able to redirect to 1.jsp. If we upload a Small Execl file, in this case redirection works fine. but we are facing issue with large Excel files. Browser does not show 1.jsp page. We are using RequestDispatcher to forward request to 1.jsp.
    Is there any issue with the connection timeout. our application is in tomcat which is beyond Apache. All our request go through Apache.
    I missed one more thing. from debugging we found out that tomcat is redirecting properly to 1.jsp but we are not able to see that page in the browser. The Entire process takes around 20 mins. We tried by sending direct request to tomcat on port 8080 bypassing apache in this case it works fine for large Excel files i.e. redirection works fine if we bypass the apache.
    Please help.
    Thanks.

    I tried changing it in Tomcat server.xml and also in apache configurations. Also i tried by setting timeout in jsp page. Timeout was set for 30 minutes.
    Nothing worked.

  • Tapestry and Servlet (redirect on timeout session)

    Who knows as it is possible to organize transition on login page under conditions in web.xml
    <session-timeout>5</session-timeout>I tried through the filter there is no result.
    Design of the filter such:
    <filter>
       <filter-name>login</filter-name>
       <filter-class>.........web.RedirectFilter</filter-class>
    </filter>And it is map of the filter
    <filter-mapping>
       <filter-name>login</filter-name>
       <url-pattern>/*</url-pattern>
    </filter-mapping>

    Bump.

  • Redirecting URL Servlet not working

    Hi all,
    All my JSPs are located in pages folder of my Application's Web Context. I need to redirect JSP URLs to the pages folder. For example if user requests http://localhost:8080/RedirectJSPApp/test.jsp then I need to redirect to http://localhost:8080/RedirectJSPApp/pages/test.jsp. But if user request http://localhost:8080/RedirectJSPApp/pages/test.jsp then i dont need to do any redirection.
    So I define a Servlet:
    package com.srh.servlet;
    public class RedirectServlet
          extends javax.servlet.http.HttpServlet
       public void doGet(HttpServletRequest request, HttpServletResponse response)
             throws ServletException, IOException
          doPost(request, response);
       public void doPost(HttpServletRequest request, HttpServletResponse response)
             throws ServletException, IOException
          String contextPath = request.getContextPath();
          String requestUrl = request.getRequestURL().toString();
          String targetRequestUrl = null;
          String jspRequested = null;          
          int index = -1;
          index = requestUrl.indexOf("/pages/");
          // The JSP is not called properly;
          if (index == -1)
             // Call the JSP properly
             index = requestUrl.indexOf(contextPath);
             if (index != -1)
                targetRequestUrl = requestUrl.substring(0, index+contextPath.length());
                jspRequested = requestUrl.substring(index+contextPath.length()+1);
                targetRequestUrl += "/pages/" + jspRequested;
                response.sendRedirect(targetRequestUrl);
    }In the web.xml I wrote:
       <servlet>
          <description>This Servlet redirects JSP URLs to appropriate lcoation w.r.t. Server</description>
          <display-name>RedirectServlet</display-name>
          <servlet-name>RedirectServlet</servlet-name>
          <servlet-class>com.srh.servlet.RedirectServlet</servlet-class>
       </servlet>
       <servlet-mapping>
          <servlet-name>RedirectServlet</servlet-name>
          <url-pattern>*.jsp</url-pattern>
       </servlet-mapping>I have a test.jsp in pages folder:
    <html>
       <head>
          <title>Test</title>
       </head>
       <body>
          Inside test.jsp
       </body>
    </html>I deployed on JBoss 4.2.0. I type http://localhost:8080/RedirectJSPApp/test.jsp in my browser and it changes to http://localhost:8080/RedirectJSPApp/pages/test.jsp which is perfect but it never prints "Inside test.jsp" on the page. Why this is happening?
    If I remove RedirectServlet entries from web.xml and just type in http://localhost:8080/RedirectJSPApp/pages/test.jsp then it prints "Inside test.jsp" on the page. What I am missing here?
    TIA
    TV

    I tried forward of RequestDispatcher but still same problem:
    package com.srh.servlet;
    public class RedirectServlet
          extends javax.servlet.http.HttpServlet
       public void doGet(HttpServletRequest request, HttpServletResponse response)
             throws ServletException, IOException
          doPost(request, response);
       public void doPost(HttpServletRequest request, HttpServletResponse response)
             throws ServletException, IOException
          String contextPath = request.getContextPath();
          String requestUrl = request.getRequestURL().toString();
          String targetRequestUrl = null;
          String jspRequested = null;          
          int index = -1;
          index = requestUrl.indexOf("/pages/");
          // The JSP is not called properly;
          if (index == -1)
             // Call the JSP properly
             index = requestUrl.indexOf(contextPath);
             if (index != -1)
    //          targetRequestUrl = requestUrl.substring(0, index+contextPath.length());
    //          jspRequested = requestUrl.substring(index+contextPath.length()+1);
    //          targetRequestUrl += "/pages/" + jspRequested;
    //          response.sendRedirect(targetRequestUrl);
                jspRequested = requestUrl.substring(index+contextPath.length()+1);
                RequestDispatcher rd = request.getRequestDispatcher("/pages/" + jspRequested);
                rd.forward(request, response);
    }

  • Multiple Redirects through Servlet

    I am very new to jsp and java servlets. I am trying to put a processing page that appears while some work is done and then the servlet redirects to a output page that displays reports. I am not sure how to do this.
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //send initial redirect to a processing page
        //do some work
        RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/reportOutput.jsp");
        dispatcher.forward(request, response);
    }Any ideas?

    Use Javascript to display a hidden <div> element with some animated gif when the submit button is pressed.
    If you really want an intermediate page, then you need to fire a new thread to do the progress and use the meta refresh header or ajaxical techniques to check the current progress.

  • Redirection servlet

    I've been given the task of writing a servlet to redirect users to a different URL. The only problem I have is that I've never written a servlet before and have no clue how to proceed!
    If anyone could post the general format a servlet is supposed to follow, I'd be eternally (eternally until 5pm) grateful! Thanks

    Ok, I have the following code so far
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.io.*;
    import java.util.*;
    public class Redirection extends HttpServlet
      //Initialize global variables
      public void init(ServletConfig config) throws ServletException
        super.init(config);
      //Process the HTTP Post request
      public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
        response.setContentType("text/html");
        PrintWriter out = new PrintWriter (response.getOutputStream());
        out.println("<html>");
        out.println("<head><title>Redirection</title></head>");
        out.println("<body>");
        out.println("</body></html>");
        out.close();
        String url = "http://www.microsoft.com";  //These are the lines I added
        response.sendRedirect(url); //The rest was generated by JBuilder
      //Get Servlet information
      public String getServletInfo()
        return "Servlet.Redirection Information";
    }The rest of the code and the main method is stored in a second file that was also pre-generated for me. I know there is a lot of garbage in there, especially with the printwriter, but is this what I need or am I missing something?

  • Need help trying to figure this problem out.  Username validate on servlet.

    Hello.
    Here is my dilema. Almost everything works but the username check servlet.
    I have form that gathers information that sends to a bean to validate the forms fields. If the fields check out ok it than forwards to Vusername servlet which checks the username in the database to make sure there is not one of the same username in there. If there is the servlet redirects to a retry page notifying the user that the username is already taken. If successfull the servlet forwards to another servlet which processes all the registration information into the database.
    As i said everything works fine but the Vusername servlet. I dont think the problem is with my sql query which checks for an exsiting username with the one that was entered into the form.
    I think the problem is with my if statements. I think they are currently checking if the sql query has ran. If true do this if false do that. Which is not right.
    I need the if statments to check against the result of the sql query being true or false and than redirect depending on those variables.
    Anyway any insight would be greatly appreciated.
    Here is a copy of the Vusername servlet.
    Thanks.
    // Andy Janow
    // 03/01/05
    // Make sure the username is available.
    import java.io.*;
    import java.net.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.util.*;
    import java.sql.*;
    import Sql;
    public class Vusername extends Sql
    public void doPost( HttpServletRequest req, HttpServletResponse res )
    throws ServletException, IOException
         String user;
         String pass1;
         String pass2;
         String email;
         String sError = "/Error.jsp";
         String Failure = "You need to retry";
         String fUsername = "/usernameError.jsp";
         String fUserOb = "Username is in use already";
         // Get the username from the bean.
      user = req.getParameter("userName");
      pass1 = req.getParameter("password1");
      pass2 = req.getParameter("password2");
      email = req.getParameter("emailAddress");
      // Creating the string to check available username.  
      boolean isTaken = isUserNameTaken(user);
      // Creating the forward on error due to unavailable username selection.
       if (isTaken = true);
        req.setAttribute("fUserOb",fUserOb);
           RequestDispatcher rd = getServletContext().getRequestDispatcher(fUsername);
           rd.forward(req, res);
      // Creating the forward on Error page.
       if (isTaken = false);
        req.setAttribute("Failure", Failure);
           RequestDispatcher rd = getServletContext().getRequestDispatcher(sError);
           rd.include(req, res);
    // Sql QUERY for username.
    public boolean isUserNameTaken(String username)
        boolean isTaken = false;
        PreparedStatement ps = null;
        ResultSet rs = null;
        try
            ps = connection.prepareStatement("SELECT userName FROM Registration WHERE userName = ?");
            ps.setString(1,username);
            rs = ps.executeQuery();
            isTaken = rs.next(); // returns true if there is a row returned
        catch (SQLException e)
            e.printStackTrace();
        finally
        { // ALWAYS clean up your resources
            try
                if (rs != null) rs.close();
            } catch (SQLException e) { /* close quietly */ }
            try
                if (ps != null) ps.close();
            } catch (SQLException e) { /* close quietly */ }
        return isTaken;
    public void destroy()
      try
       connection.close(); // Closing the db connection (cleanup).
      catch( Exception e )
       System.err.println( "Problem closing the database" );
    }

    Thanks for the repli.
    I forgot to come back here and fix the topic to issue solved.
    In the past hour sience i posted i was able to work through and fix the problem.
    Was with my if statment... Just an error of typing to fast i suppose and not really going through my code very thouroughly.
    Think how i had the code posted i was using the
    if statment to check if the sql statement was true , than another if statment to check if was false..
    Thing is, is that i already was checking if the username was in the database or not in the actual sql statment block by assinging weather the it was (true) or it was not (false) to the resultset variable.
    So in my if statments higher up in the code i just needed to reformat them correctly, from if true do this, and if false do this... To if some variable is present do this, else do this.
    And now it works great.
    Just in case anyone was wondering.
    But thanks for the repli and interest :)

  • Calling servlet problem in iPlanet web server.

    Hello, friends.
    I have installed iPlanet web server 6.0. After installation I am using the default virtual server only. Thus, for all testing pages also, I use the default Document Root only (C:\iplanet\servers\docs\testsite) (I think, here "docs" is the default document root, right? If I am wrong, please correct me). I have got 2 JSP pages and 1 servlet. I put the JSP pages, into "testsite" folder and put the servlet into a folder called "myservlets" (C:iplanet\servers\docs\myservlets).
    The jsp1.jsp page calls the servlet.class and in return the servlet redirects to jsp2.jsp page.
    My question is: what paths should I use in jsp1.jsp file and in servlet.class file?
    Thanks in Advance for all your help,
    ~ Nirav

    There is a major security breach in authenticating
    iPlanet Web Server 6.0 SP3 and SP4 using Sun ONE
    Directory Server. Using a valid user id, any
    password except null string would allow user access
    the restricted resources. iPlanet Web Server 6.0 SP5
    and 4.1 SP12 worked fine with similar configuration.Did you get an answer for this?
    We are having the exact same problems with our iPlanet Web server 6.0 SP3.
    thank you.

  • Loosing TITLE info on redirect...please help.

    For some reason I'm losing the <TITLE> info on a .jsp page. I'm getting the 'Untitled Document' at the top of the browser, even though I've specified it within the abc.jsp page.
    Process:
    - url to xyz servlet (http://host/servlet/nav.abc)
    - the servlet redirects to 'abc.jsp' page.
    servlet uses
    rd = sc.getRequestDispatcher("/jsp/abc.jsp");
    rd.forward(request,response);
    for redirect.
    abc.jsp sample code:
    <%@ include file="../includes/nocache.jsp"%>
    <%@ include file="../includes/header.jsp"%>
    <%@ page import="cam.*,database.*,java.text.*, java.util.*" %>
    <%
    some code
    %>
    <HTML>
    <HEAD>
    <TITEL>abc page</TITLE>
    </HEAD>
    <BODY>
    HTML code
    </BODY>
    </HTML>
    Thanks in advance.

    couple of things may happen
    1) you <TITEL>abc page</TITLE> spell on first "Title" is wrong correct titel to title - if this is a typo while posting check the following also
    2) The included JSP <title> should be changed --
    Thanks
    Happy Coding

  • Problem with Servlet Tutorial

    I am going through the servlet tutorial with a specific end in mind. I found a section that I think relates exactly to what I want to do. I want to have servlet redirect the user to another URL. The following code is given as an example.
    public class Dispatcher extends HttpServlet {     
       public void doGet(HttpServletRequest request,      
          HttpServletResponse response) {     
          request.setAttribute("selectedScreen",     
             request.getServletPath());     
          RequestDispatcher dispatcher = request.     
             getRequestDispatcher("/template.jsp");     
          if (dispatcher != null)     
             dispatcher.forward(request, response);     
       public void doPost(HttpServletRequest request,      
    }The problem is that I can't compile this. There is no HttpServletRequest.getRequestDispatcher(String) method. Am I misssing something here? Am I even on the right track?

    An extract from one of my servlets that redirects to
    another URL is
    this:response.sendRedirect(response.encodeRedirec
    URL("NoLogon"));But it appears you want to
    forward, rather than redirect. There's a difference,
    but I don't exactly know what it is. The forwarding
    example in my servlets book looks like
    this:RequestDispatcher dispatcher =
    getServletContext().getRequestDispatcher(address);
    dispatcher.forward(request, response);
    I tried pasting your first example into my code and got the follwoing error:
    Method encodeDirectURL(java.lang.String) not found in interface javax.servlet.ServletResponse
    It seems like there is still something missing here. When I look at the API I only see four methods for this class.

Maybe you are looking for

  • JAVA Exe+JAVA Program Scheduling

    I have following 3 subquestions: 1. How do I convert a .class file to .exe 2. How do i add my java program to a scheduler so that it runs periodically 3. How do I make my java program run in background Please mail me at [email protected]

  • Words/Phrases That Throw Up Red Flags for You

    I was working on an issue in the PrPro Forum (this THREAD), and the word "hacked" came up. I assume that the user had flashed his firmware in his camera to attain some feature, that it was not originally intended to have. This got me to thinking abou

  • Process order Closing problem..

    Hi... When i try to close the process order using CORM...i m getting error as...... "Unprocessed future change recs for order  prevent del. flag/completion" Plz can anybody help me on this issue... Also now if I try to cancel the order using CORS...i

  • I am trying to cut a section in a track but it won't select.

    I am editing an audio track and am trying to cut a section, but for some reason I can't get it to select.  Whenever I click in the region I want to cut, a flex bar comes up but I can't actually select the region.  Any tips on what else I can try?

  • Promise Technology's Pegasus Storage - will it be ok with Lightroom?

    I have Lightroom 3.4 and use a 15" Macbook Pro i7 with 8 Gig of RAM (latest hardware - just purchased) and a Thunderbolt Cinema Display.  I am considering purchasing Promise Technology's Pegasus RAID storage as an external drive.  http://www.promise.