Solved

Forwarding to a new jsp without passing quesry string parameters

Posted on 2003-12-11
12
377 Views
Last Modified: 2010-04-01
All :
Is there any to forward to a new JSP ( lets says Test2.jsp ) without passing Query string parameters from another JSP ( lets says Test1.jsp ).
But the limitation is
1) i should not use response.sendReidrect() method
2) The redirect should not pass the Query string parameters from original request to new JSP

I am trying to use RequestDispatcher.redirect(request,response) , but it is passing the Query string parameters to new JSP.

Thanks in advance for your help.

Srinivas
0
Comment
Question by:divvela
  • 3
  • 3
  • 2
  • +2
12 Comments
 
LVL 2

Accepted Solution

by:
anthony_castillon earned 84 total points
ID: 9923626
Use this:

<jsp:forward  .......>
       <jsp:param name="param1"  value="value1"/>
       <jsp:param name="param2"  value="value2"/>

</jsp:forward>
0
 
LVL 2

Expert Comment

by:anthony_castillon
ID: 9923633
0
 

Author Comment

by:divvela
ID: 9924479
Anthony,
<jsp:forward  .......> is also passing Query string parameters from original request to New JSP. I don't want to pass the query string parameters to new JSP.
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 15

Expert Comment

by:jimmack
ID: 9924737
I can't see any documented way around this (though I don't have as much experience with Servlets/JSP as some of the other experts here).

divvela, could you elaborate a bit about why you need to strip the parameters?  Some insight might allow one of us to see a different way of approaching the problem.
0
 

Author Comment

by:divvela
ID: 9925082
jimmack,
I have two JSP's Test1.jsp and Test2.jsp. We will get a request to Test1.jsp with some query string parameters
like this http://server/test1.jsp?par1=1&par2=2....etc
Whenever one of the QueryString parameter(par1,par2 etc....) values are not in the form we expect our JSP will throw ILLEGALARGUMENTEXPECTION . Now what want todo is,
whenever we get the ILLEGALARGUMENTEXPECTION expection because of those query string values we want to redirect it to a Test2.jsp without Querystring values.
I can do it using response.sendRedirect(). But our code somehow does not allow todo this.
So i need a way to redirect it to Test2.jsp from Test1.jsp by stripping off QUery string parameters . Hope i have explained it in a better way. Let me know if you have further more questions .. Thanks you very much for your response.

Srinivas
0
 
LVL 2

Expert Comment

by:anthony_castillon
ID: 9925190
The query string will appear as this

http://server/test1.jsp?par1=1&par2=2....etc

if your <form method="get">.  Use "post" instead.
0
 

Author Comment

by:divvela
ID: 9925218
anthony,
 The request from a software on the client machine. Its not a website . So i cannot change it to Post method.

Srinivas
0
 
LVL 14

Assisted Solution

by:kennethxu
kennethxu earned 83 total points
ID: 9925448
I would suggest you to consider what other experts have suggested, especially I can think of any reason why response.sendRedirect cannot be used.
BUT, if you must to this, there is actually a way to do it.
you'll need to define a java class which implements HttpServletRequest interface:

import java.util.*;
import java.servlet.*;
import java.servlet.http.*;

public class MyHttpRequest implements HttpServletRequest {
  HttpServletRequest raw;
  MyHttpRequest( HttpServletRequest rawRequest ) {
    this.raw = rawRequest;
  }
  public String getParameter( String name ) {
    return null;
  }
  public Enumeration getParameterNames( ) {
    return Collections.enumeration( Collections.EMPTY_LIST );
  }
  public Map getParameterMap() {
    return Collections.EMPTY_MAP;
  }
  public Type allOtherMethodsInInterface( parameter list ) {
    [return] raw.allOtherMethodsInInterface( parameter list );
  }
  ......
}

then you can do:
RequestDispatcher.redirect( new MyHttpRequst(request), response)

let me know if you have futher enquires.
0
 
LVL 6

Assisted Solution

by:jarasa
jarasa earned 83 total points
ID: 10001477
If you just want to call another JSP without any params just do it with JavaScript:

.......
<SCRIPT>
function forward(){
top.location.href="test2.jsp"
}
</SCRIPT>
......
<input type=button OnClick="javascript:forward();">
.....
or directly:
.....
<input type=button OnClick="javascript:top.location.href='test2.jsp';">
.....
Javier
0
 
LVL 6

Expert Comment

by:jarasa
ID: 10001488
If you don't want the Client to interact with your JSP you can also do this
Test1.jsp
..........
Your JSP CODE
.......
<HTML>
<HEAD>
</HEAD>
<BODY>

<P> Please Wait..... </P>

<SCRIPT>
top.location.href="test2.jsp"
</SCRIPT>
</BODY>
</HTML>

This will call Test2.jsp without any parameters and and without client inteeact.

But as Kennethxu says I don't know why you don't want to make a response.sendRedirect....

Javier
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Suggested Solutions

Some of the SEO trends we might expect in 2017.
Most MSPs worth their salt are already offering cybersecurity to their customers. But cybersecurity as a service is wide encompassing and can mean many things.  So where are MSPs falling in this spectrum?
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

840 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