3 Replies - 747 Views - Last Post: 06 January 2008 - 03:52 PM

#1 jowharshamshiri  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 65
  • Joined: 24-December 07

how can i access the vars specified in the browser address bar?

Posted 04 January 2008 - 03:43 AM

hi guys,
im failry new to web development and i got this silly question:
how do you access vars specified in the browser address bar when requesting the page?
take this url for example:
www.site.com\index.jsp?action=welcome
how can i access the variable <action> specified in the url and read its value inside index.jsp?

This post has been edited by jowharshamshiri: 04 January 2008 - 03:45 AM

Is This A Good Question/Topic? 0
  • +

Replies To: how can i access the vars specified in the browser address bar?

#2 _net  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 147
  • Joined: 23-September 07

Re: how can i access the vars specified in the browser address bar?

Posted 04 January 2008 - 09:52 PM

If you did it in PHP it'd be easy.

$_GET['action'];

so for example: echo $_GET['action']; <-- this would print out Welcome.
Was This Post Helpful? 0
  • +
  • -

#3 MitkOK  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 32
  • View blog
  • Posts: 403
  • Joined: 09-August 07

Re: how can i access the vars specified in the browser address bar?

Posted 05 January 2008 - 06:56 AM

Javascript :

function getUrlVars() {

   var vars = [], hash;
   var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');

   for(var i = 0; i < hashes.length; i++) {

		hash = hashes[i].split('=');
		vars.push(hash[0]);
		vars[hash[0]] = hash[1]; 
  }

  return vars;

}

Was This Post Helpful? 0
  • +
  • -

#4 jowharshamshiri  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 65
  • Joined: 24-December 07

Re: how can i access the vars specified in the browser address bar?

Posted 06 January 2008 - 03:52 PM

thanks alot guys.
both of those work.

ps : i used this servlet:
import javax.servlet.http.*;
import java.io.*;
import javax.servlet.*;

public class URLParameter extends HttpServlet{
		public void doGet(HttpServletRequest request,HttpServletResponse response)
		throws IOException, ServletException{
				response.setContentType("text/html");
				PrintWriter out = response.getWriter();
				out.println(request.getParameter("action"));
		}
}


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1