Get variables from jsp

Hi
I have a jsp file that sets som strings and now I wan't to get hold of them from a javabean. Is it possible? I set the strings like this in the jsp file:
String theString = "Hello";
request.setAttribute("theString", theString);To get them from a jsp page i just include the file.
I know it may not be the best way but this is how it is done.
Thanks in advance.

Hi
I'm not quit shore of what you mean but I already have all variables in some jsp files and now I wan't to use them when I output from javabean. This is how I do if I wan't to show "Hello" in a tablecell in jsp:
<td><%=request.getAttribute("theString") %></td>but how is it done if I wan't "Hello" in a string from a javabean like this:
String whatIWant = ????;

Similar Messages

  • Parse A Variable From JSP to JSP

    hi all,
    how can i parse a variable from jsp page to another jsp page. i do not call jsp page . so how can i do this

    do u mean passing???
    try scope application

  • How to get variable from javascript to jsp

    Hi,
    I put a JSP page but in one frame it has a JAVAScript running. The Javascript is a viewer that user can input bounding coordinate and see updated results. Once user input the bounding coordinate in the javascript, I would like to make
    that variable available to the entire JSP, so I can submit all query (include the parameter user input in the JSP form) from jsp at a time. How to do this?
    Thanks
    Kenny

    Hi,
    Okey here is the code. There are three frames.
    1. KennyFrame.htm
    2. MapFrame.htm
    3. kenny.jsp
    Once you run the "KennyFrame.htm" it will show a page
    with two top-bottom frames. The top is
    "MapFrame.htm".
    The bottom is "kenny.jsp"
    Once user input something on MapFrame.htm, it will do
    a process in Javascript then update the "new answer".
    I will need to put that "new answer" into the "What's
    mapFrame Input? " Text box. Therefore, when user click
    on submit on kenny.jsp frame. The "new answer" will be
    submitted.
    Code:
    MapFrame.htm (the main page)
    <body bgcolor="#FFFFFF" text="#000000">
    Newmapframe
    <center>
    <form name=form>
    <input type=text name=box value="type in here!">
    <input type=button value="Convert"
    onClick="javascript:changeCase(this.form.box)">
    </form>
    </center>
    </body>
    </html>
    MapFrame.htm (the code with javascript on top frame)
    <html>
    <head>
    <title>Map Frame Document</title>
    <meta http-equiv="Content-Type" content="text/html;
    charset=iso-8859-1">
    <SCRIPT LANGUAGE="JavaScript">
    <!-- Begin
    function changeCase(frmObj) {
    var tmpStr;
    tmpStr = "Some answer!";
    frmObj.value = tmpStr;
    // End -->
    </script>
    </head>
    <body bgcolor="#FFFFFF" text="#000000">
    Newmapframe
    <center>
    <form name=form>
    <input type=text name=box value="type in here!">
    <input type=button value="Convert"
    onClick="javascript:changeCase(this.form.box)">
    </form>
    </center>
    </body>
    </html>
    kenny.jsp (jsp on bottom frame for final submit)
    <html>
    <head><title>Number Test</title></head>
    <body bgcolor="white">
    <font size=4>
    <form method=get>
    What's mapFrame Input? <input type=text name=guess>
    <input type=submit value="Submit">
    </form>
    </font>
    </body>
    </html>
    let us the say the name of the frame in which kenny.jsp is placed be 'kennyframe' and u change the javascript function 'changeCase()' in MapFrame.htm to below:
    function changeCase(frmObj)
    var tmpStr;
    tmpStr = "Some answer!";
    frmObj.value = tmpStr;
    parent.frames["kennyframe"].document.form.guess.value = frmObj.value;

  • Problem accessing session variable from jsp

    Hi!
    I get an error retrieving a session variable from inside a JSP declaration scriptlet....
    Something like this code in a JSP page:
    <%!
    public void funtion1() {
    String parameter1 = session.getAttribute("parameter1");
    %>I have seen that I have available getContextServer() method and from there I could call getAttribute("parameter1") . But the thing is that the attribute I want to retrieve was stored in session by another Jsp page.
    Any solutions are welcome
    Cheers
    Victor

    Appropriately the above is one the reasons also You cannot use JSP implicit objects from the declaration tag. However we can think of a small workaround by passing the reference like the one discussed below
    <%!public void funtion1(HttpSession session) {
    String parameter1 = session.getAttribute("parameter1").toString();
    }%>
    <% funtion1(session);%>Hope that helps :)
    REGARDS,
    RaHuL

  • How to get variable from subpanel

    Hi,
    May I know how to get the variable from the subpanel VI?
    Please see my VI, when I start the test in any of the subpanel, I can't get any variable in the "Get All Control Values Variant" indicator.
    Is there any wrong?
    Thanks.
    Solved!
    Go to Solution.
    Attachments:
    My VI.zip ‏62 KB

    Try this:
    Put a For Loop at the end, just before you close the reference to the VIs. like shown below.
    I am not allergic to Kudos, in fact I love Kudos.
     Make your LabVIEW experience more CONVENIENT.
    Attachments:
    Modified 2x2.vi ‏33 KB

  • Passing variables from JSP to workflow

    I want to pass some variables from my JSP forms to a workflow. The workflow is triggered when I call processLaunch.jsp with the name of the workflow. I couldn't figure out a way to have the input fields in my JSP form passed to the workflow.
    If anyone can provide me with some answer, I'd greatly appreciate it.

    <Property name='postURL'>
    <block>
    <concat>
    <s>user/processLaunch.jsp?id=</s>
    <ref>ConstantData.REGISTERED_PROCESSES.WF_COMMON_ITARUPDATE</ref>
    </concat>
    </block>
    </Property>
    I have this code on the form...how should I pass a op_enduserId from here to my workflow. Can I pass it by query string &op_enduserId=enduserId

  • Getting variables from FlashMX

    i am trying to build my first FlashMX form that gets processed by a servlet...
    it's a simple form, just getting values from 2 textfields and one combo box...
    i created a new LoadVars called formData..
    i then declared my variables ( ie formData.name_txt = ""; )
    now, i want to send this info by 'POST'...
    where do i start?
    THANKS!

    Use forms - the only way to send data using post method, like
    <form name="myform" method="post">
    </form>Somewhere within form you have to supply inputs containing values
    of your vars
    Paul

  • Need help to get JS variable from JSP???i have partial soultion

    Hi everyBody
    here a littil desciption about wht i need:
    the user should Input value by (prompt) in javascript, then the value will be assigned to JS variable
    and i need the value which the user input but in JSP
    so i do like this
    <script>
    var gg;
    function getF(){
      gg = prompt("yes","input name"); 
    </script>JSP+JS,, both in same page
    now JSP code
    String newname = "<script>document.writeln(gg)</script>";now the problem is->
    i need pass the newname variable to the method renameTo() which belong to FILE class
    but i face problem with it cuz newname variable will not be assigned, it will execute the statment each time i use newname varible????
    while renameTo() method should take parameter type File.
    i hope i put al the details about my problem
    any help please???

    BalusC:
    i've tried ur way:
    this is the JS function
    <script>
    var userInput;
    function getF(){
    userInput = prompt("yes","input name");
    return userInput;
    </script>and here where i call the JS function and then pass the returned value
    out.print("<a href = index.jsp?'newName=javascript:getF()'><img src = folder.jpeg width = 48 height = 48 /></a>");i got the parameter here
    String newPath = request.getParameter("newName");
    out.print("newnameObject = "+newPath);but it return null????
    any explain???!!!!
    bst rgds
    Edited by: Mr.Carlito on Jan 8, 2008 3:53 AM

  • Getting values from jsp in portlet

    Hi,
    I want to know if I submit values from a jsp page how can get those values in the portlet class (extends Generic portlet). I have tried accessing using actionRequest.getParameter() and also renderRequest.getParameter(). But I get null value .
    Do I need to add the below shown line also to the jsp -
    <portlet:defineObjects/>
    I am working with JSR 168 portlet. I am posting part of the jsp down let me know how can I go about this problem.
    <%@ page language="java"%>
    <form name="userForm" method="post">
    <table>
    <tr>
         <td>User Name</td>
         <td>
              <input type="text" name="userName"/>
         </td>
    </tr>
    <tr>
         <td>
              <input type="submit" label="Save"/>
         </td>
    </tr>
    </table>
    </form>
    Thanks

    Hi ,
    I created a sample portlet the way it is in notepad portlet and it worked fine for me . But the main difficulty is I am trying to convert an existing code and there the form submission happens in java script .The following code is used to submit the form and there I am not able to get the values in processAction().
    Please check the java script code and let me know if I can change it in someway which can make the submitted values available in the processAction().
    document.forms[0].action ='<portlet:actionURL><portlet:param name="mode" value="dummyVal"/></portlet:actionURL>';
    document.forms[0].submit();
    Thanks..

  • Need help with getting variable from static

    Hello,
    What I am building is an application that prompts for username/password before it shows the main screen. Once they have successfully logged in, I need to assign the username that they used, in order to use it for a button event if the make any updates.
    Here is the code that I have tried to use.
    public String username;
    ///This set's the public variable username
    public void setUserName(String UserName){
    username = UserName;
    /////////////////Here is where they login, and assign the name to setUsername
    public static void main(String args[]) throws SQLException {
    java.awt.EventQueue.invokeLater(new Runnable() {
    public void run() {
    JFrame frame = new JFrame();
    JTextField userName = new JTextField();
    JTextField passWord = new JTextField();
    Object[] options = {"OK","CANCEL"};
    Object[] msg = {"UserName:", userName, "Password:", passWord};
    final JOptionPane op = new JOptionPane(msg, JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION){};
    JDialog dialog = op.createDialog(frame, "Please Login");
    dialog.show();
    int result = JOptionPane.OK_OPTION;
    try {
    result = ((Integer)op.getValue()).intValue();
    }catch(Exception uninitializedValue){}
    if(result == JOptionPane.OK_OPTION) {
    String userID = userName.getText();
    String passID = passWord.getText();
    Main myMain = new Main();
    myMain.setUserName(userID);
    if(!userID.equals("") && !passID.equals("")) {
    new Main().setVisible(true);
    }else {
    // user cancelled
    ////here is the button event that also will need the username
    private void selButtonActionPerformed(java.awt.event.ActionEvent evt) {
    Connection conn = null;
    Statement stmt3 = null;
    Statement stmt4 = null;
    ResultSet rset3 = null;
    ResultSet rset4 = null;
    String usernum = null;
    String xemu = null;
    String loc = null;
    String ustat = null;
    String manager = null;
    String dept = null;
    String Add = "Add";
    String Update = "Update";
    String groupID = "9999";
    Vector columnNames = new Vector();
    Vector data = new Vector();
    String Manager_info[] = {"managerindex", "managers", "managername"};
    String Account_info[] = {"acctypeindex", "acctype", "acctypedesc"};
    String Group_info[] = {"groupnum", "groups", "groupcode"};
    String System_info[] = {"systemindex", "systems", "systemname"};
    String Dept_info[] = {"departindex", "departments", "departname"};
    String Xemu_info[] = {"xemuindex", "xemulator", "xemudesc"};
    String Location_info[] = {"locindex", "location", "locdesc"};
    String Ustatus_info[] = {"ustatusindex", "userstatus", "ustatusdesc"};
    Date myDate = new Date();
    SimpleDateFormat formatter = new SimpleDateFormat("dd-MMM-yy");
    String today = formatter.format(myDate);
    System.out.println(username);
    I am trying to set the public username variable to what the person enters, however since I am creating a seperate instance of it, I don't believe it will work. Any help would be very much appreciated.
    Thanks.
    Josh

    I am developing in Netbeans. If I try to remove the static keyword from main(), netbeans canno't find a main to run. I have created the User class.
    Here is the main again to show what I have done.
    public static void main(String args[]) throws SQLException {
    java.awt.EventQueue.invokeLater(new Runnable() {
    public void run() {
    User user = new User();
    JFrame frame = new JFrame();
    JTextField userName = new JTextField();
    JTextField passWord = new JTextField();
    Object[] options = {"OK","CANCEL"};
    Object[] msg = {"UserName:", userName, "Password:", passWord};
    final JOptionPane op = new JOptionPane(msg, JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION){};
    JDialog dialog = op.createDialog(frame, "Please Login");
    dialog.show();
    int result = JOptionPane.OK_OPTION;
    try {
    result = ((Integer)op.getValue()).intValue();
    }catch(Exception uninitializedValue){}
    if(result == JOptionPane.OK_OPTION) {
    String userID = userName.getText();
    String passID = passWord.getText();
    user.setName(userID);
    user.setPassword(passID);
    if(!userID.equals("") && !passID.equals("")) {
    //Auth.setUserName(userID);
    //Auth.setPassword(passID);
    new Main().setVisible(true);
    }else {
    // user cancelled
    This set's the variables
    Here is the beginning of the evt that I am using to try and get the data.
    private void selButtonActionPerformed(java.awt.event.ActionEvent evt) {                                         
    Connection conn = null;
    Statement stmt3 = null;
    Statement stmt4 = null;
    ResultSet rset3 = null;
    ResultSet rset4 = null;
    String usernum = null;
    String xemu = null;
    String loc = null;
    String ustat = null;
    String manager = null;
    String dept = null;
    String Add = "Add";
    String Update = "Update";
    String groupID = "9999";
    Vector columnNames = new Vector();
    Vector data = new Vector();
    User user = new User();
    String User = user.getName();
    System.out.println(User);
    String Manager_info[] = {"managerindex", "managers", "managername"};
    String Account_info[] = {"acctypeindex", "acctype", "acctypedesc"};
    String Group_info[] = {"groupnum", "groups", "groupcode"};
    String System_info[] = {"systemindex", "systems", "systemname"};
    String Dept_info[] = {"departindex", "departments", "departname"};
    String Xemu_info[] = {"xemuindex", "xemulator", "xemudesc"};
    String Location_info[] = {"locindex", "location", "locdesc"};
    String Ustatus_info[] = {"ustatusindex", "userstatus", "ustatusdesc"};
    Date myDate = new Date();
    SimpleDateFormat formatter = new SimpleDateFormat("dd-MMM-yy");
    String today = formatter.format(myDate);
    String [] str = {
    "EmpID", "Account", "System", "Type", "Status", "UserID", "Group"
    This gives me a null on the println, how can I get the data that was entered in main()?
    Thanks,
    Josh

  • Reading Variable from JSP and pass to servlet

    hello
    i have a servlet page which transfers data to a jsp page. The jsp displays the data only. Now i want to read a string from a jsp page and then pass it to the servlet.
    How can i do it?
    thnks

    hello
    this is working fine: out.println("<input
    type=\"hidden\" name=\"bookId\" value=\"+bookId+\"
    size=\"25\">") ;
    works fine
    thnksI guess you didn't understand me. Look to the difference between the following two statements:
    out.println("<input type=\"hidden\" name=\"bookId\" value=\"+bookId+\" size=\"25\">") ;and
    out.println("<input type=\"hidden\" name=\"bookId\" value=\""+bookId+"\" size=\"25\">") ;In the first you're handling the bookId variable as String, in the second it will use the actual value of bookId.

  • Passing Variables from JSP to a servlet

    Presently I have a small Web application where by users enter data onto a jsp Page , this data then gets passed onto a servlet which then updates a sql database through a call to a sql stored procedure
    While testing I determined that when there are multiple users, sometimes users records are getting crossed, some of my data, is getting written to someone elses record....
    any thoughts on the cause......

    below is the code to the servlet
    The jsp page is a typical jsp with text boxes etc,
    package cpri;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.io.*;
    import java.util.*;
    import java.sql.*;
    public class viewfileinfoservlet extends HttpServlet {
      private static final String CONTENT_TYPE = "text/html";
      //Initialize global variables
      public void init() throws ServletException {
      //Process the HTTP Post request
      public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType(CONTENT_TYPE);
        PrintWriter out = response.getWriter();
        Connection conn = null;
        CallableStatement stmt = null;
        String sErrorMessage = "";
        String sStatus = "PS";
        String sSin = "";
        String sPSin = "";
        String sBN = "";
        String sPBN = "";
        String sSurName = "";
        String sFirstName = "";
        String sLegalName = "";
        String sTradeName = "";
        String sAddress = "";
        String sCity = "";
        String sProv_Code = "";
        String sRTSO = "";
        String sPayment = "";
        String sGSPayment = "";
        String sCompliant = "";
        String sTX11Issued = "";
        String sFYEMM = "0";
        String sFYEDD = "0";
        String sGSTStatus = "";
        String sNotes = "";
        String sRecordID = "";
        String sFYE = "";
        String sRCode = "";
        String sPostalCode = "";
        String sRemoteUser = "";
        int intRecordID = 0;
        int intRemoteUser = 0;
        int i = 0;
        String sPayorPhone = "";
        String sPayorName = "";
        response.setHeader("Cache-Control", "no-cache");
        response.setDateHeader("Expires", 0);
        response.setBufferSize(10*1024);
        sErrorMessage = "";
        sRemoteUser = request.getRemoteUser();
        sRTSO = "0";
        if (sRemoteUser.indexOf("\\") != -1)
          intRemoteUser = sRemoteUser.indexOf("\\") + 1;
          sRemoteUser = sRemoteUser.substring(intRemoteUser);
        sGSTStatus = "";
        if ( request.getParameter("lstStatus") !=null)
          sStatus = request.getParameter("lstStatus").trim();
          if (sStatus.equals("PS"))
            sErrorMessage = sErrorMessage + "Was unable to confirm File Status." + "\n";
        else
          sErrorMessage = sErrorMessage + "Was unable to confirm File Status." + "\n";
      if ( request.getParameter("txtPayorName") !=null)
       sPayorName = request.getParameter("txtPayorName").trim();
    else
       sPayorName = "";
    if (request.getParameter("txtPayorPhone") !=null)
      sPayorPhone = request.getParameter("txtPayorPhone").trim();
    else
      sPayorPhone = "";
      if ( request.getParameter("txtSin") !=null)
        sSin = request.getParameter("txtSin").trim();
      else
        sSin = "";
      if ( request.getParameter("txtPSin") !=null)
        sPSin = request.getParameter("txtPSin").trim();
      else
        sPSin = "";
      if ( request.getParameter("txtPBN") !=null)
        sBN = request.getParameter("txtPBN").trim();
      else
        sBN = "";
      if ( request.getParameter("txtPPBN") !=null)
        sPBN = request.getParameter("txtPPBN").trim();
      else
        sPBN = "";
      if ( request.getParameter("txtSurname") !=null)
        sSurName = request.getParameter("txtSurname").trim();
      else
        sSurName = "";
      if ( request.getParameter("txtFName") !=null)
        sFirstName = request.getParameter("txtFName").trim();
      else
        sFirstName = "";
      if ( request.getParameter("txtLName") !=null)
        sLegalName = request.getParameter("txtLName").trim();
      else
        sLegalName = "";
      if ( request.getParameter("txtTName") !=null)
        sTradeName = request.getParameter("txtTName").trim();
      else
        sTradeName = "";
      if ( request.getParameter("txtAddress") !=null)
        sAddress = request.getParameter("txtAddress").trim();
      else
        sAddress = "";
      if ( request.getParameter("txtCity") !=null)
        sCity = request.getParameter("txtCity").trim();
      else
        sCity = "";
      if ( request.getParameter("txtProv_Code") !=null)
        sProv_Code = request.getParameter("txtProv_Code").trim();
      else
        sProv_Code = "";
      if ( request.getParameter("txtPostal") !=null)
        sPostalCode = request.getParameter("txtPostal").trim();
      else
        sPostalCode = "";
      if ( request.getParameter("lstRecCode") !=null)
        sRCode = request.getParameter("lstRecCode").trim();
      else
       sRCode = "";
      if ( request.getParameter("txtRTSO") !=null)
        sRTSO = request.getParameter("txtRTSO").trim();
      else
        sRTSO = "";
      if ( request.getParameter("txtsPayment") !=null)
        sPayment = request.getParameter("txtsPayment").trim();
      else
        sPayment = "0";
      if ( request.getParameter("txtGSPayment") !=null)
        sGSPayment = request.getParameter("txtGSPayment").trim();
      else
        sGSPayment = "0";
      if ( request.getParameter("lstCompliant") !=null)
        sCompliant = request.getParameter("lstCompliant").trim();
      if ( request.getParameter("lstTX11Issued") !=null)
        sTX11Issued = request.getParameter("lstTX11Issued").trim();
      sFYEMM = "";
      if ( request.getParameter("txtMM") !=null)
        sFYEMM = request.getParameter("txtMM").trim();
      sFYEDD = "";
      if ( request.getParameter("txtDD") !=null)
        sFYEDD = request.getParameter("txtDD").trim();
      if ( request.getParameter("lstGSTStatus") !=null)
        sGSTStatus = request.getParameter("lstGSTStatus").trim();
      if ( request.getParameter("Notes") !=null)
        sNotes = request.getParameter("Notes").trim();
      else
        sNotes = "";
      if ( request.getParameter("RecordID") !=null)
        sRecordID = request.getParameter("RecordID").trim();
      if (sFYEMM.equals("0") && sFYEDD != "0")
        sErrorMessage = "Was unable to confirm FYE." + "\n";
      if (sFYEDD.equals("0") && sFYEMM != "0")
        sErrorMessage = "Was unable to confirm FYE." + "\n";
      sFYE = "1999" + "-" + sFYEMM + "-" + sFYEDD;
      if (sStatus.equals("PA")||sStatus.equals("A")||sStatus.equals("PCR")||sStatus.equals("PCU"))
         // check for errors
           try
             i = Integer.parseInt(sRTSO);
           catch (NumberFormatException ex)
             sErrorMessage = sErrorMessage + "Recipient TSO must be a numeric field and is required field when file  is being closed." + "\n";
         if (sRCode.equals("0"))
           sErrorMessage = sErrorMessage + "Recipient Code is a required field when file is being Closed." + "\n";
      if (sErrorMessage.length()!=0)
              //display error page
              request.setAttribute("ERRORS", sErrorMessage);
              request.getRequestDispatcher("ViewFileInfoError.jsp").forward(request,response);
              out.flush();
              return;
      else
              try
                conn = CPRI_Connection.GetSQL_APPConnection();
                String call = "{call usp_UpdateCPRIRecord(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)}";
                stmt = conn.prepareCall(call);
                stmt.setString(1, sRecordID);
                stmt.setString(2, sStatus);
                stmt.setString(3, sSin);
                stmt.setString(4, sPSin);
                stmt.setString(5, sBN);
                stmt.setString(6, sPBN);
                stmt.setString(7, sSurName);
                stmt.setString(8, sFirstName);
                stmt.setString(9, sLegalName);
                stmt.setString(10, sTradeName);
                stmt.setString(11, sAddress);
                stmt.setString(12, sCity);
                stmt.setString(13, sProv_Code);
                stmt.setString(14, sRTSO);
                stmt.setString(15, sPayment);
                stmt.setString(16, sGSPayment);
                stmt.setString(17, sCompliant);
                stmt.setString(18, sTX11Issued);
                stmt.setString(19, sFYE);
                stmt.setString(20, sGSTStatus);
                stmt.setString(21, sRCode);
                stmt.setString(22, sPostalCode);
                stmt.setString(23, sNotes);
                stmt.setString(24, sRemoteUser);
                stmt.setString(25, sPayorName);
                stmt.setString(26, sPayorPhone);
                stmt.registerOutParameter(27, java.sql.Types.INTEGER);
                stmt.execute();
                if (stmt.getInt(27) != 0) {
                  intRecordID = stmt.getInt(27);
                else {
                  intRecordID = 0;
                sRecordID = String.valueOf(intRecordID);
               stmt.close();
               if (conn !=null){
                 try {
                   conn.close();
                 }catch (SQLException ex1){
                   //trow new Servlet exception
             catch(SQLException ex){
               throw new ServletException(ex);
        //RequestDispatcher disp;
        //disp = getServletContext().getRequestDispatcher("EventConfirmation.jsp");
        request.setAttribute("Action",sRecordID);
        request.getRequestDispatcher("ViewFileInfo.jsp").forward(request, response);
        //out.println("sEventID:" + sEventID + "<br>");
        //disp.forward(request, response);
      //Clean up resources
      public void destroy() {
    }

  • How to get variable from another class?

    I have 2 classes. In first I have int variable. In second class I need to get this variable value. How I can make it?
    import javax.microedition.lcdui.*;
    import java.io.*;
    import java.util.*;
    public class ChooseLessons extends Form implements CommandListener, ItemStateListener
         ChoiceGroup lessons;     // Choice Group of preferences
         Dictionary     dictionary;
         int volumeSize;
         ChooseLessons(Dictionary dictionary)
              int volumeSize = 15;
         public void commandAction(Command c, Displayable s)
              if (c == Dictionary.BEGIN_CMD) {
                   new TeachForm(dictionary, this);
    import javax.microedition.lcdui.*;
    import java.util.*;
    public class TeachForm extends Form implements CommandListener     
         Dictionary               dictionary;
         ChooseLessons          lessons;
         TeachForm(Dictionary dictionary, ChooseLessons lessons) {
              super(Locale.WORD);
              this.dictionary = dictionary;
              this.lessons = lessons;
              lessons.volumeSize(); // HERE I NEED VARIABLE VALUE FROM PREVIOUS CLASS
    }Edited by: Djanym on Mar 16, 2009 4:43 PM

    This is a classic problem that coders run into when trying to get their head around object-oriented programing. Since you have a class that should be modeled after a real world object, as far as that object is concerned, no one else needs to know the details of it - without asking nicely. This is where you should set up some getters and setters, which are methods that allow fields in a class to reveal themselves or allow their states to be changed in a orderly fashion.
    There are a number of fields that never need to be known outside of the class. Then there are some fields you would like to let people know about, but don't want them to have the ability to change them. In the example below, there are to getter methods allow return of the necessary fields. If you made these public, there is a possibility that someone utilizing this field may change it outside of its intended use, or access them without them being ready for public consumption.
    Class test {
    //These private variables are only visible from the class
    private int grade1 = 0;
    private int grade2 = 0;
    private int grade3 = 0;
    private float average = 0;
    private int gradeboost = 0;
    //This method sets the gradeboost field to one desired by the instructor
    void setboost(int boost) {
    gradeboost = boost;
    //These methods accept test scores and compute the average for three test
    //Notice that the calculated average may not be the true average of the three test scores
    //because of the possibility of gradeboost calculation being greater than 1
    void test1(int score) {
             grade1 = score;
             average = (grade1 + grade2 + grade3 + gradeboost)/3;
    void test2(int score) {
             grade2 = score;
             average = (grade1 + grade2 + grade3 + gradeboost)/3;
    void test3(int score) {
             grade3 = score;
             average = (grade1 + grade2 + grade3 + gradeboost)/3;
    //This is a getter method, which provides read access to the private variable average
    //If someone just had public access to the grades and wanted to take their own average
    //They would miss how the gradeboost field affects the final outcome.
    float getAverage() {
        return average;
    //Here is a getter method, which accepts an argument to determine which test score to return
    //Notice that this isn't the true testscore, but it has been modified by the gradeboost field.
    //If the user had public access to the true testscore, it wouldn't take into account the gradeboost calculation!!
    //This is how a getter can control exactly what a user has access to.
    float get testScore(int test) {
    float testresult = 0;
    if (test = 1) {
           testresult = (grade1+ gradeboost) / 3;
    if (test = 2) {
           testresult = (grade2+ gradeboost) / 3;
    if (test = 3) {
           testresult = (grade3+ gradeboost) / 3;
    return testresult;
    }

  • Pass a variable from JSP to embedded Script

    I can't seem to find a way around this. Please help.
    I need to get the value of "item.likes" from the JSP page and put it into the embedded Script.
    Can I do that ?
    Nothing I came up with worked, and I found nothing on the Internet. I searched for a lot of things. Is the only way to just implement that JSP page as a servlet ?
    Please see code below
    thank you !!
    Dennis
    <sql:setDataSource var="profileDS"
    url="jdbc:mysql://localhost/test"
    driver="com.mysql.jdbc.Driver"
    user="xxx" password="xxx" />
    <sql:query var="profileQuery" dataSource="${profileDS}">
    SELECT likes
    FROM profiles where likes=?
    <sql:param value="${param.likes}"/>
    </sql:query>
    <c:forEach var="item" items="${profileQuery.rows}">
    c:out value="${item.likes}"/>
    <%
    String dd= request.getAttribute("item.likes");
    out.write(dd); //does not work here ... should print out the value of item.likes
    %>
    </c:forEach>

    Some funny scooping with forEach. But if you put a "<c:set var="item.likes" value="${item.likes}" scope="request"/>" first inside the loop it is possible to use that value for your script. But using your sample the printout gets funny. All script output first and then the EL-created out.
    Hopes this helps you anyway.
    /Micael Ericsson

  • Passing variables from JSP to XSL

    Hi;
    I need to pass some variables with string value in them to an xsl page to store them in a <param..> tag... ive so far been unsuccessful at that, the following are my codes.. : Does anyone know how to pass it directly into the xsl page ?...
    jsp page :
    <%
                                                                     String compNames;
                                                                     String[] listRight;
                                                                     compNames = (String)session.getAttribute("compNames");
                                                                     listRight = request.getParameterValues("listRight");
                                                                                         String yr1 = listRight[0];
                                                                                         String yr2 = listRight[1];
                                                                                         String yr3 = listRight[2];
                                                                                         String yr4 = listRight[3];
                                                                                         String yr5 = listRight[4];
                                                                                         pageContext.setAttribute("yr1", yr1);
                                                                                         pageContext.setAttribute("yr2", yr2);
                                                                                         pageContext.setAttribute("yr3", yr3);
                                                                                         pageContext.setAttribute("yr4", yr4);
                                                                                         pageContext.setAttribute("yr5", yr5);
                                                                                         pageContext.setAttribute("compN", compNames);
                                                                     %>
    xsl page :
    <xsl:param name="CoCode"><core:param name="compN" value="${compN}"/></xsl:param>
         <xsl:param name="yr1"><core:param name="yr1" value="${yr1}"/></xsl:param>
         <xsl:param name="yr2"><core:param name="yr2" value="${yr2}"/></xsl:param>
         <xsl:param name="yr3"><core:param name="yr3" value="${yr3}"/></xsl:param>
         <xsl:param name="yr4"><core:param name="yr4" value="${yr4}"/></xsl:param>
         <xsl:param name="yr5"><core:param name="yr5" value="${yr5}"/></xsl:param>

    and to display the xsl, ive used to following Include code :
    <jsp:include page ="./ratios.xsl"></jsp:include>
    i dont need to link it together with as xml as ive already done so in ratios.xsl file... i think there might be some mistake in using the include code... can anyone point out to me if im wrong... thanks

Maybe you are looking for