?
Solved

Retrieve address bar information

Posted on 2006-06-07
8
Medium Priority
?
295 Views
Last Modified: 2008-01-09
I have a jsp which when I view it through the browser it the url browser address bar it has:

http://localhost:9080/xxxx/GetArcActivity.do?top_menu=home.

How do I get my java program to read this and pull the top_menu value of home out of it?
0
Comment
Question by:TheVeee
8 Comments
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 300 total points
ID: 16856582
0
 
LVL 92

Assisted Solution

by:objects
objects earned 300 total points
ID: 16857420
URL url = new URL("http://localhost:9080/xxxx/GetArcActivity.do?top_menu=home.");
String query = url.getQueryString();
String top_menu = query.split("=")[1];
0
 
LVL 10

Accepted Solution

by:
mukundha_expert earned 400 total points
ID: 16858311
-- > http://localhost:9080/xxxx/GetArcActivity.do?top_menu=home.

this is actually a request to the "http://localhost:9080/xxxx/GetArcActivity.do" with parameters top_menu = home.

In your jsp you can call
String home =  request.getParameter("top_home");
now pass the home value to ur java class.

0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 30

Expert Comment

by:Mayank S
ID: 16858625
>> How do I get my java program

Is that a separate program or do you mean the JSP/ servlet itself?
0
 
LVL 13

Expert Comment

by:Webstorm
ID: 16859833
0
 
LVL 13

Expert Comment

by:Webstorm
ID: 16859835
->  request.getParameter("top_menu")
0
 
LVL 5

Author Comment

by:TheVeee
ID: 16862439
These methods work if your in the regular java servlet or activity as we call it.  I guess I need to be more pointed with my question.  Im using struts and i have built a helpler class or adaptor code for my jsp page.  My problem is that in the adaptor page, I cant get addressibility to the request object at all.  I can get addressiblity to the bean, but not a single variable which should be in the request.  I have the activity or servlet which call this page set the attribute, but I cant get addressiblity in the adaptor program.  I will give more points for the solution.  I have done this before.. just missing something!!

Heres the code, JSP page below... then the Adaptor page below which does the work.  (Im usning struts tag libiraires).

Test.JSP Code:
-------------------------------------------------------------------------------------------------
<%@ taglib uri="/WEB-INF/lib/jakarta-struts-1.0.jar" prefix="struts" %>
<%@ taglib uri="/WEB-INF/lib/jakarta-taglibs-page-1.0.jar" prefix="pg" %>
<jsp:useBean id="ArcHeaderAdaptor" scope="page" class="com.arc.adaptor.HeaderAdaptor"/>
<jsp:setProperty name="HeaderAdaptor" property="session" value= "<%= session %>"/>
<jsp:setProperty name="HeaderAdaptor" property="request" value= "<%= request %>"/>
<%@ page import="arc.web.controller.*"%>
<html>
<head>
<jsp:useBean id="inputBean" scope="session" class="arc.web.model.JSPInputPageBean"/>
<script language="javascript">
      <!--
      function getNextSetRecords( prevNextStartRecord ){
            document.genericForm.prevNextStartRecord.value = prevNextStartRecord;
            document.genericForm.submit();
      }
      -->
</script>

<%
      boolean canAddAndFix = false;
      

      WebSecurity webSecurity = new WebSecurity();
      String userId = (String)session.getAttribute(webSecurity.SESSION_ACF2ID_NAME);
      //System.out.println("userId is "+ userId);
      if(userId != null  && userId.length()>3){
            String resultString = userId.substring(0,3);
            //System.out.println("result string is "+ resultString);
               if (resultString.equalsIgnoreCase("a2i") || resultString.equalsIgnoreCase("afa")){
                       canAddAndFix = true;
                 }
         }      
         //System.out.println("canAddAndFix "+ canAddAndFix);  
            
%>

      <title>ARC - <struts:present name="inputBean"><struts:write name="ArcHeaderAdaptor" property="inputBean.title"/> <struts:write name="ArcHeaderAdaptor" property="serverTitle"/></struts:present> - KRDC</title>
      <link rel="stylesheet" href="<struts:write name="ArcHeaderAdaptor" property="contextPath"/>/univincludes/globalnav/css/template.css" type="text/css">
      <!-- PLEASE NOTE:  Items referred from dynamic links  will NOT be searchable by
      the PinPoint full text search engine.  You must specify metatags to regain this functionality -->  

        <script language="javascript">var server_name='<struts:write name="ArcHeaderAdaptor" property="server_name" />';</script>
        <!-- <script language="javascript">var isArcDeveloperLoggedIn=<%//=inputBean.isArcDeveloperLoggedIn() %>;</script> -->
    <script language="javascript">var isArcDeveloperLoggedIn=<%=canAddAndFix %>;</script>
<struts:equal name="ArcHeaderAdaptor" property="isHomeFlag" value="true"><script language="javascript">var HM_OtherMenuPage='<struts:write name="ArcHeaderAdaptor" property="contextPath"/>/menus/home.jsp';</script></struts:equal>
<struts:equal name="ArcHeaderAdaptor" property="isAdminFlag" value="true"><script language="javascript">var HM_OtherMenuPage='<struts:write name="ArcHeaderAdaptor" property="contextPath"/>/menus/admin.jsp';</script></struts:equal>
<struts:equal name="ArcHeaderAdaptor" property="isArcServerFlag" value="true"><script language="javascript">var HM_OtherMenuPage='<struts:write name="ArcHeaderAdaptor" property="contextPath"/>/menus/arc_server.jsp';</script></struts:equal>
<struts:equal name="ArcHeaderAdaptor" property="isHistoryFlag" value="true"><script language="javascript">var HM_OtherMenuPage='<struts:write name="ArcHeaderAdaptor" property="contextPath"/>/menus/arc_server.jsp';</script></struts:equal>

<!--USE THE FOLLOWING META TAGS TO IMPROVE SEARCH RESULTS. -->
<!--Enter as many keywords (separated by commas) to describe the contents of this page. -->
<!--Summary will be displayed on the search results page.  If you do not enter content for
      summary, the search engine will generate one. -->
<!--Be sure to add a descriptive title between the title tags for displaying in search results. -->
<meta name="keywords" content="">
<meta name="summary" content="">
<!--The meta tags below have not been implemented yet, but will be in the future.
Check http://onestop.corp.sprint.com frequently for updates. -->
<meta name="contenttype" content="">
<meta name="vendor" content="">
<meta name="pubdate" content="">
<meta name="subject" content="">
<meta name="category" content="">
<meta name="contact" content="">
<meta name="location" content="">
<meta name="activities" content="">
<meta name="businesspurpose" content="">
</head>

<body marginleft="0" margintop="0" leftmargin="0" topmargin="0" marginheight="0" marginwidth="0" link="#ff0000" vlink="#663333">

<table width="100%" cellpadding="0" cellspacing="0" border="0">
  <tr height="70">
      <td height="70" class="topFrameCell">
        <!--#*******include virtual="/univincludes/globalnav/gnav_top.inc" -->
      <% //This file was changed to JSP so that the contextPath could be used to retrieve
            //images inside the test environment
         //<jsp:include page="/univincludes/globalnav/gnav_top.inc" flush="true" /> %>
    <jsp:include page="/univincludes/globalnav/gnav_top.jsp" flush="true" />
 
      </td>
  </tr>

  <tr height="26">
      <td height="26" class="topTitleRow">
        <!-- begin site title header -->
        <table border="0" cellspacing="0" cellpadding="0" width="793" height="26">
            <tr>
              <!-- first top nav row (left fade and top site title and links) -->
              <td height="26" width="141" class="topFrameCell"><img src="<struts:write name="ArcHeaderAdaptor" property="contextPath"/>/univincludes/globalnav/images/spacer.gif" width="141" height="1" alt="" border="0"></td>
              <td height="26" width="652" nowrap>
                  <table border="0" cellspacing="0" cellpadding="0">
                    <tr height="26" width="652">
                        <td width="7" height="26" align="left"><img src="<struts:write name="ArcHeaderAdaptor" property="contextPath"/>/univincludes/globalnav/images/nav_corner.gif" width="7" height="26" alt="" border="0"></td>
                        <td width="360" height="26"> <span class="siteTitle">ARC - Automated Routing and Completions</span>
                        </td>
                        <td width="245" height="26" align="right"> <a href="mailto:ArcNational.List@mail.sprint.com" class="topRightLinks">Contact</a>
                        </td>
                    </tr>
                  </table>
              </td>
              <td height="26" width="40" nowrap>&nbsp;</td>
            </tr>
        </table>
        <!-- end site title header -->
      </td>
  </tr>
  <tr height="20">
      <td height="20" class="topSubNavRow">
        <!-- begin nav buttons -->
        <table border="0" cellspacing="0" cellpadding="0" width="541" height="20">
            <tr height="19">
              <!-- second top nav row (nav buttons) -->
              <td height="19" width="141"><img src="<struts:write name="ArcHeaderAdaptor" property="contextPath"/>/univincludes/globalnav/images/nav_fade.gif" width="141" height="19" alt="" border="0"></td>
              <td height="19" width="400" nowrap>
                  <table border="0" cellspacing="0" cellpadding="0">
                    <tr height="19" width="400">
                        <td width="1" height="19" class="leftSectionBorder"><img src="<struts:write name="ArcHeaderAdaptor" property="contextPath"/>/univincludes/globalnav/images/spacer.gif" width="1" height="1" alt="" border="0"></td>
<struts:equal name="ArcHeaderAdaptor" property="isHomeFlag" value="true"><td width="98" height="19" class="currentSection" align="center"><span class="topNavButton">Home</span></td></struts:equal>
<struts:equal name="ArcHeaderAdaptor" property="isHomeFlag" value="false"><td width="98" height="19" align="center"><a href="<struts:write name="ArcHeaderAdaptor" property="contextPath"/>/index.jsp?top_menu=home" class="topNavButton">Home</a></td></struts:equal>
                        <td width="1" height="19" class="rightSectionBorder"><img src="<struts:write name="ArcHeaderAdaptor" property="contextPath"/>/univincludes/globalnav/images/spacer.gif" width="1" height="1" alt="" border="0"></td>
                        <td width="1" height="19" class="leftSectionBorder"><img src="<struts:write name="ArcHeaderAdaptor" property="contextPath"/>/univincludes/globalnav/images/spacer.gif" width="1" height="1" alt="" border="0"></td>
<struts:equal name="ArcHeaderAdaptor" property="isHistoryFlag" value="true"><td width="98" height="19" class="currentSection" align="center"><span class="topNavButton">History</span></td></struts:equal>
<struts:equal name="ArcHeaderAdaptor" property="isHistoryFlag" value="false"><td width="98" height="19" align="center"><a href="<struts:write name="ArcHeaderAdaptor" property="contextPath"/>/audit/audit_tables.jsp?server_name=HISTORY" class="topNavButton">History</a></td></struts:equal>
                        <td width="1" height="19" class="rightSectionBorder"><img src="<struts:write name="ArcHeaderAdaptor" property="contextPath"/>/univincludes/globalnav/images/spacer.gif" width="1" height="1" alt="" border="0"></td>
                        <td width="1" height="19" class="leftSectionBorder"><img src="<struts:write name="ArcHeaderAdaptor" property="contextPath"/>/univincludes/globalnav/images/spacer.gif" width="1" height="1" alt="" border="0"></td>
  <struts:present name="ArcHeaderAdaptor" property="isAdminLoggedOn"><struts:equal name="ArcHeaderAdaptor" property="isAdminLoggedOn" value="true">
      <struts:equal name="ArcHeaderAdaptor" property="isAdminFlag" value="true"><td width="98" height="19" class="currentSection" align="center"><span class="topNavButton">Admin</span></td></struts:equal>
      <struts:equal name="ArcHeaderAdaptor" property="isAdminFlag" value="false"><td width="98" height="19" align="center"><a href="<struts:write name="ArcHeaderAdaptor" property="contextPath"/>/servlet/arc.web.controller.CtrlServlet?CtrlPage=arc.web.controller.arcweb.ArcCalendar&server_name=HISTORY&top_menu=admin" class="topNavButton">Admin</a></td></struts:equal>
                       <td width="1" height="19" class="rightSectionBorder"><img src="<struts:write name="ArcHeaderAdaptor" property="contextPath"/>/univincludes/globalnav/images/spacer.gif" width="1" height="1" alt="" border="0"></td>
                        <td width="1" height="19" class="leftSectionBorder"><img src="<struts:write name="ArcHeaderAdaptor" property="contextPath"/>/univincludes/globalnav/images/spacer.gif" width="1" height="1" alt="" border="0"></td>
      <struts:equal name="ArcHeaderAdaptor" property="isArcServerFlag" value="true"><td width="98" height="19" class="currentSection" align="center"><span class="topNavButton">Arc Server</span></td></struts:equal>
      <struts:equal name="ArcHeaderAdaptor" property="isArcServerFlag" value="false"><td width="98" height="19" align="center"><a href="<struts:write name="ArcHeaderAdaptor" property="contextPath"/>/database_list.jsp" class="topNavButton">Arc Server</a></td></struts:equal>
  </struts:equal>
  </struts:present>
                        <td width="1" height="19" class="rightSectionBorder"><img src="<struts:write name="ArcHeaderAdaptor" property="contextPath"/>/univincludes/globalnav/images/spacer.gif" width="1" height="1" alt="" border="0"></td>
                    </tr>
                  </table>
              </td>
            </tr>
            <tr height="1">
              <td height="1"><img src="<struts:write name="ArcHeaderAdaptor" property="contextPath"/>/univincludes/globalnav/images/spacer.gif" width="1" height="1" alt="" border="0"></td>
            </tr>
        </table>
        <!-- end nav buttons -->
      </td>
  </tr>
  <tr>
      <td valign="top" height="400">
        <!-- begin middle section of page (minimum height = 400 -->
        <table border="0" cellspacing="0" cellpadding="0" width="100%" height="400">
            <tr>
              <td valign="top" width="142" class="leftNavCol" background="<struts:write name="ArcHeaderAdaptor" property="contextPath"/>/univincludes/globalnav/images/blackline.gif">
                  <!-- begin left column -->
                  <table width="142" border="0" cellspacing="0" cellpadding="0" >
                    <tr>
                        <td class="topFrameCell">
                          <table border="0" cellspacing="0" cellpadding="0" width="141">
                              <tr height="15" bgcolor="#FFFFFF">
                                <td height="15" width="100%">
            &nbsp;
<!--      
                                    <table border="0" cellspacing="4" cellpadding="0">
                                      <tr>
                                          <td> <a href="#" class="leftNavLink">Home</a> </td>
                                      </tr>
                                    </table>
                                </td>
                              </tr>
                              <tr height="1" class="leftDiv">
                                <td height="1" width="14%"><img src="/univincludes/globalnav/images/spacer.gif" width="1" height="1" alt="" border="0"></td>
                              </tr>
                              <tr height="15" bgcolor="#FFFFFF">
                                <td height="15" width="100%">
                                    <table border="0" cellspacing="4" cellpadding="0">
                                      <tr>
                                          <td> <a href="#" class="leftNavLink">Login</a> </td>
                                      </tr>
                                    </table>
                                </td>
                              </tr>
                              <tr height="1" class="leftDiv">
                                <td height="1" width="100%"><img src="/univincludes/globalnav/images/spacer.gif" width="1" height="1" alt="" border="0"></td>
                              </tr>
                              <tr height="15" bgcolor="#FFFFFF">
                                <td height="15" width="100%">
                                    <table border="0" cellspacing="4" cellpadding="0">
                                      <tr>
                                          <td> <a href="#" class="leftNavLink">Documentation</a> </td>
                                      </tr>
                                    </table>
-->
                                </td>
                              </tr>
                              <tr height="1" class="leftDiv">
                                <td height="1" width="100%"><img src="<struts:write name="ArcHeaderAdaptor" property="contextPath"/>/univincludes/globalnav/images/spacer.gif" width="1" height="1" alt="" border="0"></td>
                              </tr>
                          </table>
                        </td>
                    </tr>
                  </table>
                  <!-- end left column -->
              </td>
              <td width="100%" valign="top" class="bodyText">
<!--
 ***************************   begin body of page ****************************************
-->



--------------------------------------------------------------------------------------------------

*************************************************************
*************************************************************
Test.java
package com.arc.adaptor;

import javax.servlet.ServletContext;

import arc.web.model.JSPInputPageBean;

/**
 * Adapts request and session objects for display on the JSP.
 */
public class TestAdaptor extends ListAdaptor {
      // Will be a mixture of flags and actual values until later
      // We have converted all pages to tag libs and boolean
      private String physicalServerName;
      private JSPInputPageBean inputBean = new JSPInputPageBean();
      private boolean homeFlag = false;
      private boolean adminFlag = false;
      private boolean historyFlag = false;
      private boolean arcServerFlag = false;
      private boolean serverNameFlag = false;
      private boolean serverTitleFlag = false;
      private String top_menu = "";
      private String server_name = "";
      private String server_title = "";
      private String contextPath = "";
      public ArcHeaderAdaptor() {
            super();
      }

      public void prepareSessionData() {
            physicalServerName = context.getPhysicalServerName();
            inputBean = (JSPInputPageBean) session.getAttribute("inputBean");
            ServletContext application = session.getServletContext();

            if(application.getServletContextName() != null){
                  contextPath = "/" + application.getServletContextName();
            }else{
                  contextPath = "";
            }


            physicalServerName = context.getPhysicalServerName();

                               // Problem is here, request object is ALWAYS NULL
            if (request != null) {
                  if (request.getParameter("top_menu") != null) {
                        top_menu = request.getParameter("top_menu");
                  } else {
                        top_menu = "";
                  }
                  if (request.getParameter("server_name") != null) {
                        server_name = request.getParameter("server_name");
                  } else {
                        server_name = "";
                  }
            } else {
                  server_name = "";
                  top_menu = "";
            }
            top_menu = determineTopMenu(top_menu);
      }

      public void prepareRequestData() {
            //Nothing to do right now
      }

      /**
       * @return
       */
      public String getPhysicalServerName() {
            return physicalServerName;
      }
      
      /**
       * @return
       */
      public String determineTopMenu(String topmenu) {
            if ("home".equalsIgnoreCase(topmenu)) {
                  homeFlag = true;
            }
            else if ("admin".equalsIgnoreCase(top_menu)) {
                    adminFlag = true;
            }
            else  {
                if (! "HISTORY".equalsIgnoreCase(server_name)) {
                      arcServerFlag = true;
                      top_menu = "arc_server";
                    }
                    else {
                          historyFlag = true;
                        top_menu = "history";
              }
            }
            return topmenu;             
      }

      /**
       * @return
       */
      public String getServerTitle() {
            String HISTORY_SERVER_HOST = "";

            if (context.getPhysicalServerName()
                  == null | context.getPhysicalServerName().equals("")) {
                  HISTORY_SERVER_HOST = "KDARCP28";
            } else {
                  HISTORY_SERVER_HOST = context.getPhysicalServerName();
            }
            if (HISTORY_SERVER_HOST.equalsIgnoreCase(server_name)) {
                  server_name = "HISTORY";
            }

            if (!(server_name == null || server_name.equals(""))) {
                  server_title = " (" + server_name + ")";

            }
            return server_title;
      }

      /**
       * @return
       */
      public String getServerName() {
            return server_name;
      }

      /**
       * @return
       */
      public String getTop_menu() {
            return top_menu;
      }

      /**
       * @return
       */
      public boolean getIsAdminFlag() {
            return adminFlag;
      }

      /**
       * @return
       */
      public boolean getIsArcServerFlag() {
            return arcServerFlag;
      }

      /**
       * @return
       */
      public boolean getIsHomeFlag() {
            return homeFlag;
      }



      /**
       * @return
       */

      public JSPInputPageBean getInputBean() {
            return inputBean;
      }

      /**
       * @return
       */
      public boolean getIsHistoryFlag() {
            return historyFlag;
      }

      /**
       * @return
       */
      public String getServer_name() {
            return server_name;
      }

      /**
       * @return
       */
      public String getServer_title() {
            return server_title;
      }

      /**
       * @return
       */
      public boolean getIsServerNameFlag() {
            return serverNameFlag;
      }

      /**
       * @return
       */
      public boolean getIsServerTitleFlag() {
            return serverTitleFlag;
      }

      /**
       * @return
       */
      public String getContextPath() {
            return contextPath;
      }

}
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 16865271
:-)
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses
Course of the Month16 days, 3 hours left to enroll

850 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