?
Solved

what is equavalent of location.href in jsp?

Posted on 2005-02-28
5
Medium Priority
?
609 Views
Last Modified: 2013-12-10
hi experts,
     below is my code .


public class Str
{
     public static String Replace(String sSource, String sFrom, String sTo)
     {
          int index =0;
          System.out.println("1");
          String dest = "";
          System.out.println("2");
          index = sSource.indexOf(sFrom);
         
          System.out.println("3");
          while (index >= 0)
          {
               
               System.out.println("4");
               dest = sSource.substring(0, index);
               System.out.println("5");
               dest += sTo + sSource.substring(index + sFrom.length());
               System.out.println("6");
               sSource = dest;
               System.out.println("7");
               index = sSource.indexOf(sFrom, index + sTo.length());
               System.out.println("8");
          }
          if (dest == "")
          {
              System.out.println("9");
               dest = sSource;
               System.out.println("10");
          }
          return dest;
     }
}


<%
   Str s =new Str();
%>

<a href="#" onclick="javascript:location.href='<%=s.Replace(request.getRequestURL,"-1","-11");%>'">clickhere</a>






output of request.getRequestURL is below

http://abc.com/webapp/wcs/stores/Store1/StoreCatalogDisplay.jsp

out put of  javascript alert location.href

http://abc.com/webapp/wcs/stores/servlet/StoreCatalogDisplay?param1=100¶m2=401¶m3=-1

i tried request.getRequestURL and request.getQueryString ... but no success?

i want to replace param3=-1 to param3=-11


0
Comment
Question by:saleemkhan
[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
  • 3
5 Comments
 
LVL 7

Expert Comment

by:damonf
ID: 13419662
call request.getParameterNames()  ... this will give you and Enumeration of all the request params.  Loop through each and append to the jsp name ... when you hit param3 change its value before writing it out.
0
 
LVL 7

Expert Comment

by:damonf
ID: 13419678
request.getQueryString() only works when you actually included params in the URL ... it won't get params submitted by a form.
0
 
LVL 7

Accepted Solution

by:
damonf earned 500 total points
ID: 13419772
So basically you'd have

Enumeration e = request.getParameterNames();
String paramString = "?";
String amp = "";
String currName = "";
while(e.hasMoreElements()){
   currName = (String)e.nextElement();
   paramString += amp + currName + "=" + java.net.URLEncoder.encode(request.getParameter(currName),"UTF-8")
   amp = "&";
}


......................

<a href="#" onclick="javascript:location.href='<%=request.getRequestURI() + paramString%>'">clickhere</a>


You can use your replace function anywhere you want to change the -1 to -11.
0

Featured Post

ATEN's HDBaseT Presentation at InfoComm 2017

Hear ATEN Product Manager YT Liang review HDBaseT technology, highlighting ATEN’s latest solutions as they relate to real-world applications during her presentation at the HDBaseT booth at InfoComm 2017.

Question has a verified solution.

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

Upgrading Tomcat – There are a couple of methods to upgrade Tomcat is to use The Apache Installer is to download and unzip and run the services.bat remove|install Tomcat6 Because of the App that we are working with, we can only use Tomcat 6.…
There are numerous questions about how to setup an IBM HTTP Server to be administered from WebSphere Application Server administrative console. I do hope this article will wrap things up and become a reference for this task. You need three things…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

764 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