Solved

Forwarding to a new jsp without passing quesry string parameters

Posted on 2003-12-11
12
366 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
 
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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

A Short Story about the Best File Recovery Software – Acronis True Image 2017
What is Backup? Backup software creates one or more copies of the data on your digital devices in case your original data is lost or damaged. Different backup solutions protect different kinds of data and different combinations of devices. For e…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

705 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

19 Experts available now in Live!

Get 1:1 Help Now