?
Solved

URL address

Posted on 2002-06-06
15
Medium Priority
?
186 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
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 
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 200 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

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

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

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses
Course of the Month12 days, 4 hours left to enroll

752 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