Solved

URL address

Posted on 2002-06-06
15
180 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
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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
where is session ID cache stored 1 46
Eclipse Neon and jdk 1.8.0 11 126
Eclipse IDE - Cannot copy/paste from console output 8 124
Spring Framework HTTPSession management 1 21
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)
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

929 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

12 Experts available now in Live!

Get 1:1 Help Now