String manipulation: php to jsp

Im converting a menu generation program from PHP to JSP.
Every page in my site has been allocated a page Id.
A pages pageId determines how the primary navigation of the page displays.
My Question
I need to determine the sub Menu parent id To do this in php I can just take the int value of the pageId string to get 2
<?php
$pageId = "2.1.3.4";
$subMenuParentId = intval($pageId);
?>
how can I do this in JSP ? Is there a better solution.
<%
String pageId = "2.1.3.4";
%>

You might find this test program novel...
import java.text.*;
public class msgfmttest
    public static void main(String[] args)
     MessageFormat msgfmt = new MessageFormat("{0,number,integer}.{1,number,integer}.{2,number,integer}.{3,number,integer}");
     String pageId = "2.1.3.4";
     try {
         Object[] levels = msgfmt.parse( pageId );
         int level1 = ( (Long)levels[0] ).intValue();
         int level2 = ( (Long)levels[1] ).intValue();
         int level3 = ( (Long)levels[2] ).intValue();
         int level4 = ( (Long)levels[3] ).intValue();
         System.out.println("level 1: " +  level1);
         System.out.println("level 2: " +  level2);
         System.out.println("level 3: " +  level3);
         System.out.println("level 4: " +  level4);
     catch(ParseException exc) {
         System.err.println("pageId is invalid");
}

Similar Messages

  • String Manipulation in JSP

    Gidday All,
    I am converting an application from PHP to JSP
    in PHP I am able to explode a strings parts into an array.
    For example
    my string = "1.21.32.45.232";
    I want jsp to return an array containing the parts of this string separated by dots into an array.
    Any help appreciated.
    Thank You
    Colin

    Thanks everyone for your help,
    I knocked this up but don't get any output?
    Any help appreciated.
    Thank You
    Colin
    <html>
    <head>
    </head>
    <%@ page language="java" import="java.util.StringTokenizer" %>
    <body>
    <%
    StringTokenizer st = new StringTokenizer("123.21.56.23", ".");
    while ( st.hasMoreTokens() ){
    System.out.println( st.nextToken() );
    %>
    </body>
    </html>

  • String manipulation in JSTL

    Hello All
    I'm a just a beginner and I'm need to write a web page that is totally based on JSTL. I found out that the standard java tab lib in JSTL doesnt really support string manipulation or regular expression like in perl.
    As such, I would like to know what are the different options (like adding servlets/javabeans/etc) can i add to my JSTL page so that i can perform complex string manipulation to a data entered by the user in the text box?
    Some of the operations that I wish to carry out on the data are:
    1. check if data contains certain characters, strings
    2. joining and spliting strings
    3. find length of the string
    4. find the position of certain character in a string
    5. check if string match certain pattern.
    and many more.
    Would greatly appreciate if you guys can help to provide some light.
    Regards
    Beginner....

    You might find MicroNova YUZU JSP tag library (http://sourceforge.net/projects/micronova-yuzu) useful, especially if you need to support both JSP 1.2 and 2.0. Hope this helps.

  • String Manipulation in BI Publisher Report Paramater

    Hi,
    My Problem is that I am not able to do string manipulation on BI Publisher report Prameters.
    Actually I want to Show Deptno-Dname in Menu(LOV).and when I select Certain combination like '10-Accounting',and while passing the parameter:Dept I wanted to Cut the department no(10) using string manipulation functions provided by oracle in Data Model(Query) in where clause like (where deptno=to_number(substr(:Dept,1,2)).
    This query is working fine in other application like TOAD,But not giving results in BI Publisher Report.
    It's also not giving any error while saving or running the report.
    Please suggest any solution.

    even I tried the following query in data model..
    select DISTINCT EMP.EMPNO as EMPNO,
    EMP.ENAME as ENAME,
    EMP.JOB as JOB,
    DEPT.LOC as LOC
    from SCOTT.DEPT DEPT,
    SCOTT.EMP EMP
    where emp.DEPTNO=DEPT.deptno
    and DEPT.deptno=nvl(to_number(substr(:department,1,2)),DEPT.deptno)
    But the Parameter which I want to pass say Department('10-Accounting'),
    Still it is showing employees from all departments.

  • Converting PHP to JSP

    For work I need to convert a code that I wrote in PHP to JSP in order for it to run on our windows server.
    Trouble is, I know very little java. The script is a very simple, short email script located here: http://pastebin.com/m7b4b4e96
    Any help would be greatly appreciated.

    Perhaps this one?
    http://www.amazon.com/Murachs-Java-Servlets-Andrea-Ste
    elman/dp/1890774189/ref=pd_sim_b_5_img/002-0859111-900
    5647I have read many many JSP and Servlet books in the past and the book you mentioned (Murachs-Java-Servlets book by Andrea Steelman) is the best by far above any other books.

  • Own php or jsp files

    Hello,
    can I upload and run on apex.oracle.com my own php or jsp scripts ?
    Thank you

    No.

  • From PHP to JSP for a search-responder.php

    I have been asked to use the "search-as-you-type" solution offered up by Google at [http://code.google.com/p/search-as-you-type/|http://code.google.com/p/search-as-you-type/]. The documentation offered by Google is pretty much straight forward but of course the actual piece of code that gets the data is built in PHP and my client needs this to be used on a page serving up JSP.
    I am learning JSP and moving from PHP and ASP and learning quickly but not quick enough to finish the project.
    Would anyone be able and willing to help me convert the functions in the following PHP code into JSP?
    Thanks in advance to anyone who takes the time to help me.
    <?php
    * Copyright (C) 2006 Google Inc.
    * Licensed under the Apache License, Version 2.0 (the "License");
    * you may not use this file except in compliance with the License.
    * You may obtain a copy of the License at
    *      http://www.apache.org/licenses/LICENSE-2.0
    * Unless required by applicable law or agreed to in writing, software
    * distributed under the License is distributed on an "AS IS" BASIS,
    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    * See the License for the specific language governing permissions and
    * limitations under the License.
    * Search-as-you-type sample Ajax responder
      // Adding a cache control so that browsers won't cache Ajax requests
      header("Cache-Control: no-cache");
      header("Content-Type: text/html; charset=UTF-8");
       * Get the sample data from the text file.
       * @return array Loaded data
      function GetData() {
        $data = array();
        $file = file("test-data.txt");
        foreach($file as $record) {
          $record = explode("|", trim($record));
          if (count($record) == 4) { // Ignore invalid lines
            $data[] = $record;
        return $data;
       * Get the results based on user's query.
       * @param string $query Query
       * @param array $data Sample data
       * @return array Result array
      function GetResults($query, $data) {
        $results = array();
        $queryLength = strlen($query);
        foreach ($data as $record) {
          if (substr(strtolower($record[0]), 0, $queryLength) == $query) {
            $result = array();
            $result['name'] = $record[0];
            $result['type'] = $record[1];
            $result['content'] = $record[2];
            $result['moreDetailsUrl'] = $record[3];
            $result['style'] =
              ($query == strtolower($record[0])) ? 'expanded' : 'normal';
            $results[] = $result;
        return $results;
      // Get the data and the query
      $data = GetData();
      $query = strtolower(ltrim($_GET['query']));
      // Build response
      $response = array();
      $response['query'] = $query;
      $response['results'] = GetResults($query, $data);
      if (count($response['results']) == 1) {
        $response['autocompletedQuery'] = $response['results'][0]['name'];
      // Output response
      echo "searchAsYouType.handleAjaxResponse(";
      echo json_encode($response);
      echo ");";
    ?>

    Thanks for your comment Gimbal2.
    I have already been thoroughly surprised at how different JSP is from PHP. I am finding quite hard to wrap my head around the whole process to be honest.
    I am beginning to see that JSP and PHP work in a totally different way than each other.
    I am not technically trying to translate or convert the PHP file as much as I am trying to build a file in JSP that does the same functions. The main functions of the PHP script are commented by Google and should be easily enough re-written in JSP in order to produce similar results.
    Since the output needs to be in a JSON format when passed to the .js file you'd think this would be better suited as a .jsp file as well or even a JAVA Applet, Servlet or even a bean. Since the whole site is already built in JSP for a multitude of other functions it seems likely that adding on more to read data from a source file and send it back to the .JS would be straight forward, but I could be wrong. But again I am not familiar enough with JAVA or JSP (yet) to make heads or tails of this.
    1. // Adding a cache control so that browsers won't cache Ajax requests
    2. * Get the sample data from the text file. @return array Loaded data
    3. * Get the results based on user's query.
    * @param string $query Query
    * @param array $data Sample data
    * @return array Result array
    4. // Get the data and the query
    5. // Build response
    6. // Output response

  • How to call java with public static void main(String[] args) throws by jsp?

    how do i call this from jsp? <%spServicelnd temp = new spServicelnd();%> does not work because the program has a main. can i make another 2nd.java to call this spServiceInd.java then call 2nd.java by jsp? if yes, how??? The code is found below...
    import java.net.MalformedURLException;
    import java.io.IOException;
    import com.openwave.wappush.*;
    public class spServiceInd
         private final static String ppgAddress = "http://devgate2.openwave.com:9002/pap";
         private final static String[] clientAddress = {"1089478279-49372_devgate2.openwave.com/[email protected]"};
    //     private final static String[] clientAddress = {"+639209063665/[email protected]"};
         private final static String SvcIndURI = "http://devgate2.openwave.com/cgi-bin/mailbox.cgi";
         private static void printResults(PushResponse pushResponse) throws WapPushException, MalformedURLException, IOException
              System.out.println("hello cze, I'm inside printResult");
              //Read the response to find out if the Push Submission succeded.
              //1001 = "Accepted for processing"
              if (pushResponse.getResultCode() == 1001)
                   try
                        String pushID = pushResponse.getPushID();
                        SimplePush sp = new SimplePush(new java.net.URL(ppgAddress), "SampleApp", "/sampleapp");
                        StatusQueryResponse queryResponse = sp.queryStatus(pushID, null);
                        StatusQueryResult queryResult = queryResponse.getResult(0);
                        System.out.println("Message status: " + queryResult.getMessageState());
                   catch (WapPushException exception)
                        System.out.println("*** ERROR - WapPushException (" + exception.getMessage() + ")");
                   catch (MalformedURLException exception)
                        System.out.println("*** ERROR - MalformedURLException (" + exception.getMessage() + ")");
                   catch (IOException exception)
                        System.out.println("*** ERROR - IOException (" + exception.getMessage() + ")");
              else
                   System.out.println("Message failed");
                   System.out.println(pushResponse.getResultCode());
         }//printResults
         public void SubmitMsg() throws WapPushException, IOException
              System.out.println("hello cze, I'm inside SubmitMsg");          
              try
                   System.out.println("hello cze, I'm inside SubmitMsg (inside Try)");                         
                   //Instantiate a SimplePush object passing in the PPG URL,
                   //product name, and PushID suffix, which ensures that the
                   //PushID is unique.
                   SimplePush sp = new SimplePush(new java.net.URL(ppgAddress), "SampleApp", "/sampleapp");
                   //Send the Service Indication.
                   PushResponse response = sp.pushServiceIndication(clientAddress, "You have a pending Report/Request. Please logIn to IRMS", SvcIndURI, ServiceIndicationAction.signalHigh);
                   //Print the response from the PPG.
                   printResults(response);
              }//try
              catch (WapPushException exception)
                   System.out.println("*** ERROR - WapPushException (" + exception.getMessage() + ")");
              catch (IOException exception)
                   System.out.println("*** ERROR - IOException (" + exception.getMessage() + ")");
         }//SubmitMsg()
         public static void main(String[] args) throws WapPushException, IOException
              System.out.println("hello cze, I'm inside main");
              spServiceInd spsi = new spServiceInd();
              spsi.SubmitMsg();
         }//main
    }//class spServiceInd

    In general, classes with main method should be called from command prompt (that's the reason for main method). Remove the main method, put the class in a package and import the apckage in your jsp (java classes should not be in the location as jsps).
    When you import the package in jsp, then you can instantiate the class and use any of it's methods or call the statis methods directly:
    <%
    spServiceInd spsi = new spServiceInd();
    spsi.SubmitMsg();
    %>

  • Why passing string from applet to jsp doesn't work?

    Hi,all:
    I have a application requires applet to get client side info, then pass this "info"--string to the JSP.
    Applet code:
    try{
         URL url = new URL(getCodeBase(),"test.jsp?
    java.version=1.2.2&java.vendor=Sun);
         URLConnection conn = url.openConnection();
         conn.setDoOutput(true);
         conn.setUseCaches(false);
         conn.setRequestProperty("Content-Type", "application/octet-stream");
         conn.connect();
    } catch (Exception e) {
         System.out.println("The error is at URL:"+e.getMessage());
    My jsp code is:
    <%
    String java_version=request.getParameter("java.version");
    String java_vendor=request.getParameter("java.vendor");
    %>
    However, it doesn't work. Could anybody help me figure out?
    Thanks in advance.
    Paul

    Request Jsp with
    test.jsp?URLEncoder.encode("java.version")=URLEncoder.encode("java.version.value")&URLEncoder.encode("java.vendor")=
    URLEncoder.encode("java.vendor.value")

  • Accessing String assigned in a JSP from a Servlet?

    Hello all, I was wondering if there is a way to access a String object that was assigned by an HttpSession object in a JSP from a Servlet. What happens is, in my application a user logs in, an HttpSession object is instantiated and all of the user credentials are assigned within a JSP like:
    HttpSession httpSession = request.getSession( false );
    String userName = httpSession.getAttribute("userName);
    ...{code}
    Next, I have a Servlet (which is really just a Proxy to a different server), that I need to log some information with, namely the userName String. Is there a way I can access that String without instantiating another HttpSession object? Because when the timeout occurs (or when the user clears his cache I have found), the HttpSession becomes invalidated (even if I use  +HttpSession#getSession( true )+) and the +HttpSession#getAttribute+ call fails (userName is just null). So is this possible to do?
    Thanks in advance!                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

    dnbphysicist wrote:
    I understand you cannot recover attributes from a dead session, this is why I wanted to be able to access a variable that is pulled from the Session immediately after login so I can still get to it even once the session is dead.
    Normally a session doesn't go dead after login.
    I imagine that by using application scope the app would confuse the userName with other users that are logged in?Certainly. It was just an example. But your data clearly belongs in the session, so just keep it in the session. If the session get invalidated while it should not get invalidated, then your problem truly lies somewhere else.
    I am definitely not arguing you latter point either :) A lot of this code I inherited unfortunately from previous developers and we are in desperate need of a redesign.I wish you much luck with that.

  • Php to jsp

    Hi,
    i'am beginning of java programming...
    I need help plz to convert this part of PHP code to JSP code :
    $fp = fopen("../commun/param".$param.".txt", 'r');
    while ($str=fgets($fp,4096)) eval( "".$str.";" );
    fclose($fp);Thks

    The best way to do so is take php syntax find a way to do it in jsp and recode it

  • How to convert String to int in JSP?

    Hi,
    I set a session attribute in Servlet and want use it in JSP, How can I convert it to int or Integer?
    the line in my code doesn't work:
    int quantity=(int)session.getAttribute("vehiclequantity") ;
    Thanks in advance.
    Wolf
    +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    <HTML>
    <HEAD>
    <TITLE>Using the for Statement</TITLE>
    </HEAD>
    <BODY>
    <H1>Using the for Statement</H1>
    <%=session.getAttribute("vehiclequantity") %>;
    <%
    int loopIndex;
    int quantity=(int)session.getAttribute("vehiclequantity") ;
    out.println(quantity);
    for (loopIndex = 1; loopIndex <=2; loopIndex++) {
    out.println("This is iteration number "
    + loopIndex + "<BR>");
    %>
    </BODY>
    </HTML>

    Learning how to read errors and understand them will help you solve your problems quicker by yourself... So lets take a look at the error and classes involved...
    The error says:
    "Cannor Resolve Symbol: method valueOf(java.lang.Object) in the class java.lang.Integer" and gives you line line where the error occurs: Integer quantity = Integer.valueOf(session.getAttribute("vehiclequantity"));
    Now, if we look at the API for the Integer we notice that are are only two valueOf methods: valueOf(java.lang.String s) and valueOf(java.lang.String s, int radix). Not valueOf(java.lang.Object) method.
    Now we look at the getAttribute(java.lang.String name) method of HttpSession we see that the method returns a java.lang.Object. Now, you know you put a java.lang.String into that attribute, but the get method returns an Object. This is because you could have put any object in there, an Integer, a String, or some other class instance. But you know it is a String, so you can cast the returned value to a String, so that you will be calling the valueOf(java.lang.String s) method of Integer with the Object returned from the HtttpSession's getAttribute(java.lang.String name) method:
    Integer quantity = Integer.valueOf((String)session.getAttribute("vehiclequantity"));

  • Forward string value to next JSP page

    Hi there !
    I display several String results from query.
    Now,
    user should click the String and it forwards user to next page(page2.jsp).
    In the page2.jsp , I need to request.getParameter("end_time");
    Below is code :-
    Please help ASAP guys !
    while (outerRset.next())
    lot_number =  outerRset.getString(1);
    end_time = outerRset.getString(2);
            /*  Print TRDB LOT */
    %>
    <TR><TD> Lot Number= <%= lot_no%> </TD></TR>
    So, user should click on this lot_no and he/she gets forwarded to page2.jsp.

    Hi there !
    Page1.jsp is as such :-
    <TD><%= lot_number%></TD>
    <TD><%= end_time %></TD>
    Page2.jsp is as such :-
    String machine_end_time = new String();
    machine_end_time = request.getParameter("end_time");
    I get 'null' in Page2.jsp ! SO, it ain`t working !!!
    Do I need to include page1.jsp in page2.jsp ? If yes, how so ?
    Plz Help, people !

  • Using CharAt for String Manipulation

    Hi,
    I am new to Java and am taking a Java class. I am trying to put a social security number in "nnn-nn-nnnn" format where n is a digit 0-9. I don't know if it would work with the charAt method of the String class. Does anyone have any suggestions on how to implement this kind of manipulation.
    It would be greatly appreciated!
    Thanks,
    waggypup99

    You could just create a class for social security number.
    e.g.
    public class SSNum{
        private int _num;
        public SSNum(int number){
          _num = number;
          * take number in the form  nnn-nn-nnnn
        public SSNum(String number){
          StringTokenizer st = new StringTokenizer(number,"-");
          StringBuffer numStringB = new StringBuffer(st.nextToken());
          numStringB.append(st.nextToken());
          numStringB.append(st.nectToken());
         _num = Integer.parseInt(numStringB.toString());
       public String toString(){
          //left as fun exercise
    }

  • PHP on jsp site

    Hi all,
    I have a problem. We have a portal (weblogic) and we want to integrate into portal
    sites that developed in php. Is this possible?
    Thank you
    Tamas

    JSP without java is a bit like PHP without html
    ...only worse.Which is why I'm looking for a book or onlinetutorial
    which teaches Java with a focus on JSP.Well that's nice ...but YOU were the one who asked for
    advice from people who you may assume to know more
    than you do. Take it or leave it, makes bugger all
    dif'rence to me ... erm, learn java first.I want to learn Java, but I don't have much use for it outside of JSP. Aren't there any books which teach Java, but in the context of web development?

Maybe you are looking for

  • How do you set up Port Forwarding for ARD 2.2 in AEB N?

    Help, I'm a novice at Apple Remote Desktop (ARD) - not an IT guy, so it has to be pretty basic and detailed. How do you set up Port Forwarding for ARD 2.2 on the Apple Airport Extreme BS router, 802.11 N. I have one at each end of the internet connec

  • Adding a table to an existing table results in wrong link

    This is the code being used to add a table to a report: private ISCRTable AddLinkTable(ILinkTable linkTable, string sourceTableAlias, ConnectionInfo connectionInfo) { // construct a new Table from its name ISCRTable newTable = new Table(); newTable.C

  • Iphoto is gone, please help

    All the answers say to go retrieve iPhoto from your purchased apps. Mine is not there, nor is it hidden, I cannot drag it from my App folder as it has a white circle with a line through it. I tried retrieving from Time Machine says upgrade is not ava

  • Emac Crashes With Any Application.  Please Help?

    Can anyone please help? I have had an Emac computer for years now.  I hardly ever use it, but it has a lot of my old video files and documents on it.  I mainly work with my macbook pro.  Until recently, my Emac has been working fine, but I tried to u

  • Webservice... Binding Style: Document

    Hi, I am trying to create a web service with Document literal binding. This is what i am using.. <cfcomponent>   <cffunction name="listBooks"     access="remote"     returntype="xml"     output="yes" style = "document"> But every time when i review t