Solved

URL address

Posted on 2002-06-06
15
179 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
  • 7
  • 7
15 Comments
 
LVL 92

Expert Comment

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

Author Comment

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

Author Comment

by:DevelHelper
Comment Utility
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
 
LVL 18

Expert Comment

by:bobbit31
Comment Utility
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
Comment Utility
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
Comment Utility
do you know how to use tag libraries?
0
 
LVL 18

Expert Comment

by:bobbit31
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

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

Expert Comment

by:bobbit31
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Great job, Thanks!
0
 
LVL 18

Expert Comment

by:bobbit31
Comment Utility
welcome :)
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

744 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now