Solved

URL address

Posted on 2002-06-06
15
181 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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Cipher Configuration on Apache HTTPD 4 62
HTTPSessionBindingListernter not configured in deployment descriptor 2 52
tomcat not starting 6 45
hibernate insert example 13 28
For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
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 …
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…

776 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