Solved

URL address

Posted on 2002-06-06
15
184 Views
Last Modified: 2010-03-31
My application has a Login.jsp page with a form action="/authenticator/Login".

The following servlet java code will forword the page to the next page "Disclaimer.jsp". But the URL address in the next page is "http://csctestserver/authenticator/Login".

RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(targetURL);
dispatcher.forward(request, response);

I want a solution to make the URL address as "http://csctestserver/Disclaimer.jsp".

Thanks!
0
Comment
Question by:DevelHelper
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 7
15 Comments
 
LVL 92

Expert Comment

by:objects
ID: 7060422
Use the ora:redirect tag from http://www.thejspbook.com/jspbook.zip
0
 

Author Comment

by:DevelHelper
ID: 7061797
Thanks! but I don't know where the code I need to take a look in your zip file.
0
 

Author Comment

by:DevelHelper
ID: 7061820
I would preciate it if you can also tell me how to set up your example code to run. I have VAJ 3.5.3 installed on my windows 2000 machine.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 18

Expert Comment

by:bobbit31
ID: 7062207
if you downloaded the zip objects posted above:

it's in src/com/ora/jsp/tags/generic

all it does is reads in all parameters passed in, attaches them to your target url and does a sendredirect.
0
 

Author Comment

by:DevelHelper
ID: 7062415
I'm not sure the solution. Can you give me the code and tell me where I should add it?
0
 
LVL 18

Expert Comment

by:bobbit31
ID: 7062426
do you know how to use tag libraries?
0
 
LVL 18

Expert Comment

by:bobbit31
ID: 7062454
anyway, this is basically what it does:

Enumeration enu = request.getParameterNames();
StringBuffer encodedURL = new StringBuffer("http://csctestserver/Disclaimer.jsp");          
String strParam;

boolean isFirst = true;

while (enu.hasMoreElements()) {
     strParam = (String) enu.nextElement();

    if (!isFirst) {
       encodedURL.append('&');
     } else {
       encodedURL.append('?');
    }
   
    encodedURL.append(strParam.append("=").append(request.getParameter(strParam)));
    isFirst = false;
}

response.sendRedirect(response.encodeURL(encodedURL.toString()));
0
 

Author Comment

by:DevelHelper
ID: 7062455
I know html/xml tag. I'm not sure what you mean. I'm new to Java.
0
 
LVL 18

Expert Comment

by:bobbit31
ID: 7062466
instead of using the ora:redirect tag, you can use the code above to achieve more or less the same thing.
0
 

Author Comment

by:DevelHelper
ID: 7062539
Just in order to make my orignal question more in detail:

Login.jsp page has one "Login" button. It displays the same login page with an error message if the user enters invaild userId/password. Otherwise, it displays the Disclaimer page.

Here is a piece of java code:

RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(targetURL);
dispatcher.forward(request, response);

The request object has the same URL path for both login successful or fail:"http://csctestserver/authenticator/Login"


Question for you:
Where should the code go?Login.jsp,Disclaimer.jsp, or replace my java code shown above?
0
 
LVL 18

Expert Comment

by:bobbit31
ID: 7062546
instead of doing this:
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(targetURL);
dispatcher.forward(request, response);


you would do this:
Enumeration enu = request.getParameterNames();
StringBuffer encodedURL = new StringBuffer("http://csctestserver/Disclaimer.jsp");          
String strParam;

boolean isFirst = true;

while (enu.hasMoreElements()) {
    strParam = (String) enu.nextElement();

   if (!isFirst) {
      encodedURL.append('&');
    } else {
      encodedURL.append('?');
   }
   
   encodedURL.append(strParam.append("=").append(request.getParameter(strParam)));
   isFirst = false;
}

response.sendRedirect(response.encodeURL(encodedURL.toString()));
0
 

Author Comment

by:DevelHelper
ID: 7062587
I tried to run the code, but got an error "The method append invoked for type java.lang.String with arguments(java.lang.String) is not defined." on the following code:
encodedURL.append(strParam.append("=").append(request.getParameter(strParam)))
0
 
LVL 18

Accepted Solution

by:
bobbit31 earned 50 total points
ID: 7062595
encodedURL is a StringBuffer not a String... either way you can use this as well:

String encodedURL = targetURL;

 if (!isFirst) {
     encodedURL += "&"
 } else {
     encodedURL += "?"
  }

  encodedURL += strParam + "=" + request.getParameter(strParam);

response.sendRedirect(response.encodeURL(encodedURL));
0
 

Author Comment

by:DevelHelper
ID: 7062760
Great job, Thanks!
0
 
LVL 18

Expert Comment

by:bobbit31
ID: 7062776
welcome :)
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn different types of Android Layout and some basics of an Android App.
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question