Url in sendRedirect

Anyone please tell me if a make a call to sendRedirect with the url pattern like this /hello instead of
absolute url www.myurl.com/hello
will the redirection happen?

<quote>
sendRedirect
public void sendRedirect(java.lang.String location)
throws java.io.IOException
Sends a temporary redirect response to the client using the specified redirect location URL. This method can accept relative URLs; the servlet container must convert the relative URL to an absolute URL before sending the response to the client. If the location is relative without a leading '/' the container interprets it as relative to the current request URI. If the location is relative with a leading '/' the container interprets it as relative to the servlet container root.
If the response has already been committed, this method throws an IllegalStateException. After using this method, the response should be considered to be committed and should not be written to.
Parameters:
location - the redirect location URL
Throws:
java.io.IOException - If an input or output exception occurs
IllegalStateException - If the response was committed or if a partial URL is given and cannot be converted into a valid URL
</quote>

Similar Messages

  • URL after sendRedirect and forward

    Hi,
              As I know, after execute response.sendRedirect("URL"),the URL in the
              browser will be changed.But in this case , it is still the original one.My
              server is NT4.0,Weblogic server 5.1 sp6,ie5
              step1:
              test.jsp
              <% response.sendRedirect("in1.jsp"); %>
              <jsp:forward page="in2.jsp" />
              the result URL is http://localhost:7001/MyApp/in1.jsp (Correct)
              step2: then change test.jsp to
              <jsp:forward page="in2.jsp" />
              <% response.sendRedirect("in1.jsp"); %>
              the result URL is http://localhost:7001/MyApp/test.jsp (Correct)
              step3: change test.jsp same as step1
              <% response.sendRedirect("in1.jsp"); %>
              <jsp:forward page="in2.jsp" />
              the result URL is http://localhost:7001/MyApp/test.jsp (incorrect)
              but the title of this page is http://localhost:7001/MyApp/in1.jsp - ...
              So, what's the matter with this one , is this a bug?
              Thank you for your attention.
              

    As to which one is best, there are situations where both are useful.
    A redirect has the disadvantage that it loses all request parameters/attributes (because it creates a new request)
    The advantage to it is that if the user refreshes the screen (using F5, or pushing refresh button) it only refreshes the page that was redirected to.
    If you do an internal forward,
    You might find this article of use: http://www.theserverside.com/patterns/thread.tss?thread_id=20936

  • Url from OA page - urgent plz

    Hi ,
    I have a URL in a seeded page which should open the file repository through the URL.
    my URL value is: \\ottfs1 which should open the file repository.But i am facing the problem in opening this URL.
    http:// is being appending to the url value.I am not sure why this http:// is being appending to the URLvalue.
    when i place my cursor on the url value it shows as
    javascript:windowHandle= window.open("http://\\\\ottfs1','Renderingpage',width=800','height=15,toolbar=yes)
    so i am unable to view the file repository.
    can any one support me on this to fix. thanks.

    Anand, again thank you for your valuable information. The page is now redirecting to "http://inkolsun04:8052/OA_HTML/Temp.jsp?url=www.google.com". I used pageContext.sendRedirect(navigate); option which is working fine.
    Now, there is a problem its opening a blank page. [Not giving page not found exception]. anyway I tried to redirect to a arbitary url "http://inkolsun04:8052/OA_HTML/xyz.jsp", which is also navigating to a blank page. No, page not found exception here also.
    So, may be my jsp file has not been compiled in proper way.
    Steps what I did ->
    created a jsp file "Temp.jsp" =
    *<head>*
    *</head>*
    *<body>*
    *<p>Temp.jsp</p>*
    *<% String getUrl= request.getParameter("url"); response.sendRedirect(getUrl);%>*
    *</body>*
    Put it in $OA_HTML. [for our case -> /CLIENTDEMO11i/vis11/CLIENT_NAME/apps/apps_st/comn/webapps/oacore/html ].
    Restarted the apache server.
    Now I don't know how to solve it. Please help me on this regard.

  • URL interaction not working in Catalyst CS5

    I am using Flash Catalyst to create some tabbed navigation images. All the functions work perfectly except for one tab that is suppose to link to a product page from my company's website. I have copied the exact URL into the interaction pull-down in the program, but when I run the project that link take me to the website but doesn't display the product. It gives me the error message "This page cannot be displayed. A problem occurred loading this page.". I know the URL works outside of Catalyst if I just paste it into the bar and hit go. Why is this happening and what do I need to do to fix the issue? Any help is welcome, but be aware that I am code illiterate. Thanks!

    Yeah had this problem before, use the java.net.URLEncoder class:
    <%@ page language="java" import="java.net.URLEncoder"%>
    <%
    String url = "http://194.216.8.238:8081/merchant/merch.merchant?msgid=RP&mctid=1111242&totcp=15
    &mname=Jason Perry&mtxnid=UY675432"
    String encodedUrl = URLEncoder.encode(url);
    response.sendRedirect(encodedUrl);
    %>

  • URL Encoder not working in Netscape

    Hi All,
    I am using url encoding in my servlet for redirecting a request. The query string values has some spaces in them. The code I have used is shown below
    String mname = "Jason Perry"
    response.sendRedirect
    ("http://194.216.8.238:8081/merchant/merch.merchant?msgid=RP&mctid=1111242&totcp="+price.toString()+"&mname="+URLEncoder.encode(mname)+"&mtxnid=UY675432");
    Please note that 194.216.8.238:8081 is an IP of another server located outside our network.
    In Netscape the url is shown as http://194.216.8.238:8081/merchant/merch.merchant?msgid=RP&mctid=1111242&totcp=15
    &mname=Jason Perry&mtxnid=UY675432
    The space is not getting replaced with the plus.
    But I have observed that if the redirection is to the same server on which the servlet is running, it works fine.
    I am at loss as to why url encode is not working when routing the request to another server. I am using Netscape 4.77 .
    This is works in IE fine.
    Your inputs are appreciated.
    Thanks
    Malini

    Yeah had this problem before, use the java.net.URLEncoder class:
    <%@ page language="java" import="java.net.URLEncoder"%>
    <%
    String url = "http://194.216.8.238:8081/merchant/merch.merchant?msgid=RP&mctid=1111242&totcp=15
    &mname=Jason Perry&mtxnid=UY675432"
    String encodedUrl = URLEncoder.encode(url);
    response.sendRedirect(encodedUrl);
    %>

  • Please explain this about URL rewriting

    I am trying to write a simple example to understand URL rewriting...
    On Test1 Servlet in the doGet I have the following     
                   HttpSession session = req.getSession(true);
                   session.setAttribute("userid","123");
                   String url = resp.encodeURL("Test2.jsp");
                   System.out.println(url);
                   resp.sendRedirect(url);In the Test2.jsp I have the following
    <P>OK......</P>
    <%String id = (String)session.getAttribute("userid");%>
    <%=id%>Even though I see the URL being appended like
    http://localhost:9080/urlTest/Test2.jsp;jsessionid=00006O173z1PBf6mXOujvK25iJc:-1
    and I also see the result 123 on the screen...
    How do I know that its not using HttpSession and its using URL rewriting?

    The call to encodeURL is what is putting the "jsessionid" section into the URL. That is what it is using to maintain the session.
    So it IS using HTTPSession, but the sessionid is being maintained via URL rewriting, rather than with a session cookie.
    As an experiment, take out the call to "resp.encodeURL()" and see what the result is.
    Also, if you are using the url to redirect to, you should be using the method response.encodeRedirectURL. The rules for encoding a url being used as a redirect are slightly different from one being used as a link on a page.

  • Redirecting user to login page after session expiry

    Hi,
    Default session expiry implementation in sap EP6.0 doesn't work properly. To overcome this, we have implemented one component where we check the idle time and throw the user back to the login page if the idle time has exceeded the session expiry period. This component has been added to desktop inner page as an iView. Following is the logic put in this component.
    IAuthentication ia = UMFactory.getAuthenticator();
    ia.logout(httpRequest, httpResponse);
    httpResponse.sendRedirect("/irj/portal");
    We are successfully getting the login page after session expiry. Issue is, our portal server is running on 11111 port. We cannot change this to 80 on unix because of unix limitations for the port number. So we have put one apache web server before our portal server. Apache web server is listening on port 80 and forwarding the request to our portal server.
    Now when user is redirected to the login page, url being shown in the browser is http://<host_name>:11111/irj/portal but I am expecting http://<host_name>/irj/portal (without port). I have tried putting the full url in sendRedirect() method but that too doesn't work.
    Any help is highly appreciated.
    Regards,
    Chandra

    Hi Chandra,
    Let the URL be relative in the sendRedirect i.e.
    httpResponse.sendRedirect("/irj/portal");
    However since you have a Reverse proxy in front, the response header for redirect will not contain the address of the reverse proxy in this case, your servername without port. You have to properly configure your reverse proxy so that the HTTP Headers are changed properly before sending the response to the users.
    Check this URL,
    http://httpd.apache.org/docs/1.3/mod/mod_proxy.html#proxypassreverse
    This gives you the details on configuring your apache.
    Hope this helps.
    Ankur
    P.S. If this helps please reward points.

  • Javascript is not called in jsp page

    Hi,
    I have jsp page which actually redirect to another jsp page....
    I need to run some javascript code before redirecting to another page
    But it seems script got skipped & it goes to desired page
    code snippet:
    <%@ taglib uri="/ABCTaglib" prefix="AA" %><%response.setContentType("text/xml");%><AA:sitemap pagename="test" />
    <script type="text/javascript">
    alert("testing");
    </script
    String answerid = request.getParameter("answerid");
    String url = request.getParameter("url");
    response.sendRedirect(url);I am expecting an alert "testing" before redirect to another page.
    Thanks in advance

    Javascript is not java.
    Java/JSP runs on the server.
    javascript runs on the client, when the browser loads the page.
    As far as the server is concerned, all that javascript you have there is just template text to be echoed out in its response.
    A redirect will cancel the current response, and send a "redirect" response to tell the client where to go.
    Any output written to the response up until the redirect is discarded.
    If you want to pop up an alert, you actually have to return a response web page, with that javascript embedded in it, and then have that page navigate onwards to where you want to go (potentially using a meta refresh tag)

  • Filter Question

    Hi,
    i'm having a problem with this code...
    public class SomeFilter Class implements Filter {
    public void doFilter(ServletRequest request,
              ServletResponse response,
              FilterChain chain) {
         try {
              // a function that will throw a redirect exception
              doHttpFilter(httpServletRequest, httpServletResponse);
              // chain is a javax.servlet.FilterChain
         chain.doFilter(httpServletRequest,httpServletResponse);
         } catch(RedirectException redirectException) {
              // a function that will redirect
              handleException(redirectException);
         public void handleException(RedirectException redirectException) {
         try {
         String url = "url";
         url = httpServletResponse.encodeRedirectURL(url);
         RequestDispatcher requestDispatcher =
    requestDispatcher.forward(httpServletRequest, httpServletResponse);
         } catch (Exception exception) {
              //TODO:
    This is what happened:
    1. the doHttpFilter throws an RedirectException (the program actually expects this to happen)
    2. upon catching the RedirectException handleException(redirectException) it should forward the url...but...
    3. instead of redirecting it the code goes in to a loop (goes back and call the doFilter) until the server crashes or run out of memory
    I must admit that I don't know much about filters other than that the ChainFilter invokes the next filter and if it is on the last filter it will invoke a resource (i don't know what resource is this...does anybody know?)....is this why im having this loop?
    please give me insights...tnx

    Try this:
    public void handleException(RedirectException redirectException) {
        try {
            String url = "url";
            url = httpServletResponse.encodeRedirectURL(url);
            httpServletResponse.sendRedirect(url);
        } catch (Exception exception) {
            //TODO:

  • ORACLE ADF 11g /JSF TO  serviet (Service method) not invoking

    Hi,
    ORACLE ADF 11g /JSF TO serviet (Service method) not invoking
    My project name is : ComplProject
    inside the project im having 1 jsp say x.jsp
    work environment : (oracleADF 11g) jdev11 and weblogic server 10.3
    in x.jsp im displaying 1 go link -> when ever we click on GO link it should go to ComplServlet.java
    i tried like,
    FacesContext.getCurrentInstance().getExternalContext().redirect("/servlet/ComplServlet");
    the "ComplServlet" is an URL pattern in web.xml which points to servlet.
    but not working
    i pointed to faces-config.xml also , not working
    i tried to forward like
    FacesContext context = FacesContext.getCurrentInstance();
    ServletContext sContext = (ServletContext)context.getExternalContext().getContext();
    ServletRequest request = (ServletRequest)context.getExternalContext().getRequest();
    System.out.println("third line...............");
    HttpServletResponse response = (HttpServletResponse)context.getExternalContext().getResponse();
    response.sendRedirect("/servlet/ViewDocument");
    sContext.getRequestDispatcher("/servlet/ViewDocument").include(request, response);
    brief
    (from jsf page) after clicking on GO LINK i need to redirect or control should go to servlet ->service method
    thanks in advance
    regards,
    sandeep

    Hi,
    i tried like,
    FacesContext.getCurrentInstance().getExternalContext().redirect("/servlet/ComplServlet");
    the "ComplServlet" is an URL pattern in web.xml which points to servlet.
    but not workingUse like following.
        public HttpServletRequest getServletRequest() {
            return (HttpServletRequest)facesContext.getExternalContext().getRequest();
        public redirect(String url){
           getServletRequest().sendRedirect(getServletRequest().getContextPath() + "/servlet/ComplServlet");
        }If you are using golink as frank suggested then use it like this.
    <af:goLink text="ComplServlet" destination="/servlet/ComplServlet"/>no need of using context when using goLink,
    Regards,
    Santosh.

  • How to reset the data when the session lost?

    When I use response.sendRedirect("http://localhost:82/main.jsp")
    the session lost, because the URL before redirect is using SSL,
    "https://localhost:81/index.jsp", they use the different port,
    so the session lost, what should i do to prevent this? And how
    to reset the data?

    Create a HashMap and store it as an attribute of the servlet context. In the first servlet assign the user a key and store all session data in the HashMap under that key (use a vector, collection or user defined class).
    In the response.sendRedirect call add the key to the url:
    response.sendRedirect(url + "?key=" + userKey);
    In the second servlet get the key (request.getParameter("key")), retrieve the session data from the HashMap in the servletcontext and store in an httpsession.
    Remember to delete the entry from the HashMap so it doesn't become overly large.

  • Does send redirect work through emulator.

    hi
    i am trying to open a url through sendRedirect(url) method.when i am trying to open the jsp page through browser which uses this sendRedirect(url) and redirects it the url specified it works fine, but when i open the same jsp through emulator it throws illeagal argument exception on sendRedirect(url).
    so sendRedirect() doesnt work in emulator?
    is there any other way to open a url through jsp/servelt using emulator.

    HI Gert,
    The answer to your question is yes. I have verified this in a lab previously. As long as all the conditions for ICMP redirect have been met (source address on same net, best gateway on same net) then ICMP redirects are sent regardless of whether PBR or normal routing is being used.
    Hope that helps - pls rate the post if it does.
    Paresh

  • How to pass our request through WAP gateway.

    Hi,
    As mentioned in
    http://developers.sun.com/techtopics/mobility/midp/articles/network/index.html
    Java phones tries to reach the server directly, but how to connect to server if there is Gateway is present in between phone and web server
    (i.e. phone -> gateway -> server)
    in such a case how to make a connection to web server
    I tried with
       HttpConnection hc=Connector.open(url);
       hc.setRequestProperty("HttpProsy","proxy-ip");
    but its not working
    is there any other workaround to solve this problem
    Plz help
    @rjun

    Hi,
    use the af:commandLink and in the action property binding to your Managed Bean method. In this method, make what you need , and after that redirect to your url.
    The code will be some like that:
    public void myAction(){
    FacesContext ctx = FacesContext.getCurrentInstance();
    ExternalContext ectx = ctx.getExternalContext();
    HttpServletResponse response = (HttpServletResponse)ectx.getResponse();
    response.addCookie(new Cookie("test","test"));
    try {
    ctx.getExternalContext().redirect(URL);
    response.sendRedirect(url);
    } catch (IOException ex) {
    ex.printStackTrace();
    ctx.responseComplete();
    }

  • Calling function of JavaScript from  jsp code

    I ve to call one jsp page from other so I need to call another page
    I m trying to do by writing a javascript code for submitting the page

    while redirecting the page when I am using
    request.getParameter of hidden objects in the
    previous page its not giving the correct valuesA redirect is different from a submit, in the sense that it will create a new Request object.
    If you want to pass parameters to the next page, you will have to pass them as part of the url:
    response.sendRedirect("http://myserver/mypage.jsp?param1=value1&param2=value2");And then in mypage.jsp, you can do:
    String value1 = request.getParameter("param1");

  • Querry string problem

    hello
    I am facing a problem while working with jsf
    the problem is
    i have implemented a filter which redirects a user to login page if he is no loggen in now
    in this filter class i set a parameter in querry string which is the address of the previous from where it is redirected because he is not logged in.
    uptill now every thing is fine ie in the login page i can see the querry string append in url now on this page when user enters password etc it is varified from data base if valid then i wana redirect the the user to the page that is appended in the querry string how can i do that????
    In short
    how can i get the query string in beans action listener which is on a command button of login page???
    regards
    Shakeel Abbas

    hai BalusC
    u r right very soon i am gona take english language course.
    thanks for reply but how can i get the querry string in action method of command button
    and u fellow Selvakumar have a look.
    <filter>
    <filter-name>AccessFilter</filter-name>
    <filter-class>com.yourcompany.AccessFilter</filter-class>
    <init-param>
    <param-name>loginPage</param-name>
    <param-value>login.faces</param-value>
    </init-param>
    </filter>
    <filter-mapping>
    <filter-name>AccessFilter</filter-name>
    <url-pattern>/reports/*</url-pattern>
    </filter-mapping>
    i used this in web.xml
    and in the filter class i used is
    public class AccessFilter implements Filter {
         private FilterConfig config;
         public void destroy() {
              // TODO Auto-generated method stub
         public void doFilter(ServletRequest request, ServletResponse response,
                   FilterChain chain) throws IOException, ServletException {
              // TODO Auto-generated method stub
              HttpServletRequest servletRequest=((HttpServletRequest) request);
              HttpSession session = servletRequest.getSession();
              String url=servletRequest.getRequestURL().toString();
              url=url.substring(url.indexOf('/')+1);
              url=url.substring(url.indexOf('/')+1);
              url=url.substring(url.indexOf('/')+1);
              url=url.substring(url.indexOf('/')+1);
              if (session.getAttribute("loggedUser") == null) // if user is not logged
                                                                          // in
                   HttpServletRequest req = (HttpServletRequest) request;
                   String contextPath = req.getContextPath();
                   String loginPage = config.getInitParameter("loginPage");
                   String gotoPage=contextPath+"/"+loginPage+"?previousPage="+url;
                   HttpServletResponse res = (HttpServletResponse) response;
                   session.setAttribute("url", url);
                   res.sendRedirect(gotoPage); // then redirect to loginPage
              } else {
                   chain.doFilter(request, response);
         public void init(FilterConfig filterConfig) throws ServletException {
              // TODO Auto-generated method stub
              this.config = filterConfig;
    I hope this may be help ful to u
    regards
    Shakeel Abbas
    Edited by: Shakeel.Abbas on Sep 23, 2008 7:45 AM

Maybe you are looking for