Help with JSP / Static methods in beans...

Hi:
I am creating several javabeans as part of my application. Is it ok, to make all of them static (no global variables are used) and access in JSP's and Servlets as XXBean.method(var1, var 1). Is this a problem ? (vs creating a new XXBean and using it in every page/servlet).
I have gut feeling that static methods are better and give better memory usage and performance - as oppose in other scenario I am creating a new Bean for every page access - could not verify. and not sure not creating (new Bean) would give any problems.
Thanks for sharing.

No, static methods are not what you want. Just set the "scope" on your use-bean tag to "application".
<jsp:useBean id="xbean" class="xpackage.XXBean" scope="application" />Alternatively, if what you are trying to do is a pure "function library", then create a tag lib, and add the function definitions like this:
<function>
     <name>someMethod</name>
     <function-class>xpackage.XXBean</function-class>
     <function-signature>
     java.lang.String someMethod( java.lang.String )
     </function-signature>
</function>There is a fairly concise description of how to do this at
http://java.boot.by/wcd-guide/ch07s04.html

Similar Messages

  • NEED HELP WITH USING STATIC METHOD - PLEASE RESPOND ASAP!

    I am trying to set a value on a class using a static method. I have defined a servlet attribute (let's call it myAttribute) on my webserver. I have a serlvet (let's call it myServlet) that has an init() method. I have modified this init() method to retrieve the attribute value (myAttribute). I need to make this attribute value accessible in another class (let's call it myOtherClass), so my question revolves around not knowing how to set this attribute value on my other class using a static method (let's call it setMyStuff()). I want to be able to make a call to the static method setMyStuff() with the value of my servlet attribute. I dont know enough about static member variables and methods. I need to know what to do in my init() method. I need to know what else I need to do in myServlet and also what all I need in the other class as well. I feel like a lot of my problems revolve around not knowing the proper syntax as well.
    Please reply soon!!! Thanks in advance.

    class a
    private static String aa = "";
    public static setVar (String var)
    aa = var;
    class b
    public void init()
    a.aa = "try";
    public static void main(String b[])
    b myB = new b ();
    b.init();
    hope this help;
    bye _drag                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Help on calling static method in a multithreaded environment

    Hi,
    I have a basic question.. pls help and it is urgent.. plss
    I have a class with a static method which does nothing other than just writing the message passed to a file. Now i have to call this static method from many threads..
    What actually happens ???
    Does all the thread start to execute the static method or one method executes while the other threads wait for the current thread to complete execution?. I am not talking about synchronizing the threads...my question is what happens when multiple threads call a static method??
    Pls reply.. I need to design my project accordingly..
    Thanks
    Rajeev

    HI Omar,
    My doubt is just this..
    I wanted to know what might happen if two threads try to access a static method.. Logically only one thread can use the method since it is only only copy... but i was wondering what might happens if f threads try to access the same static method.. My Situation is this.. I have a cache which is just a hash table which will be only one copy for the whole application.. No when i get a request I have to check if the id is avaible in the cache. if it is available i call method 1 if not i call method2. Now Ideally the cache should be a static object and the method to check the id in the cache will be a normal instance method..
    I was just wondering what might happen if i make the method static.. If i can make it static i can can save a lot of space by not creating the object each time.. u know what i mean.. That y i wanted to know what happens..
    Rajeev

  • Need Help with a getText method

    Gday all,
    I need help with a getText method, i need to extract text from a JTextField. Although this text then needs to converted to a double so that i can multiply a number that i have already specified. As you may of guessed that the text i need to extract already will be in a double format.e.g 0.1 or 0.0000004 etc
    Thanks for your help
    ps heres what i have already done its not very good though
    ToBeConverted.getText();
    ( need help here)
    double amount = (and here)
    total = (amount*.621371192);
    Converted.setText("= " + total);

    Double.parseDouble( textField.getText() );

  • Help with jsp beans

    Hi ,
    I'm new to beans .Please help me on this. I have 2 jsp pages -trial.jsp and trial2.jsp and a bean class-UserInfo.java
    I'm setting the bean values from trial.jsp and trying to retrieve from trial2.jsp. But the values are coming as null. Can you please help me on this.
    Code of Trial.jsp
    <html>
    <body>
    <form name="beanTest" method="get" action="trial2.jsp">
    <table width="60%">
      <tr>
        <td width="44%">Name</td>
        <td width="56%"><label>
          <input type="text" name="name" id="name">
        </label></td>
      </tr>
      <tr>
        <td>Age</td>
        <td><input type="text" name="age" id="age"></td>
      </tr>
      <tr>
        <td>Occupation</td>
        <td><input type="text" name="occupation" id="occupation"></td>
      </tr>
      <tr>
        <td><label>                
        <jsp:useBean id="person" class="javaUtil.UserInfo" scope="request"/>
    <jsp:setProperty property="*" name="person"/>
    <input type="submit" value="Test the Bean">
    </form>
    </body>
    </html>
    Trial2.jsp
    <form>
    <jsp:useBean id="person" class="javaUtil.UserInfo" scope="request"/>
    Name<jsp:getProperty property="name" name="person"/><br>
    age:<jsp:getProperty property="age" name="person"/><br>
    job:<jsp:getProperty property="occupation" name="person"/><br>
    </form>
    UserInfo.java
    package javaUtil;
    import java.io.Serializable;
    public class UserInfo implements Serializable{
         private static final long serialVersionUID = 1L;
         private String name;
         private int age;
         private String occupation;
         public String getName()
              return this.name;
         public void setName(String name)
              this.name=name;
         public int getAge()
              return this.age;
         public void setAge(int age)
              this.age=age;
         public String getOccupation()
              return this.occupation;
         public void setOccupation(String occupation)
              this.occupation=occupation;
    Please help me.....

    Actually you're probably off on a false trail with jsp:useBean. The more up to date methods use tag libraries (typically JSTL) and access bean attributes using EL, bean expression language. E.g. you put your initial form data into a request attribute called "data" and you put:
    <input type="text" name="property1" value="${data.property1}" ....useBean is no use for binding returned fields from a form. Always remember that your JSP generates HTML and once that HTML is sent to the browser that's it, the JSP has done it's job and finished. Only with JSF, at present, does what you write in your JSP affect the processing of received form data. When you get the form data back you need to "bind" the values from the request back to the bean. A framework like Spring will do this stuff for you, but in a raw Servlet/JSP environment it's up to you.

  • Help with JSP and logic:iterate

    I have some queries hope someone can help me.
    I have a jsp page call request.jsp:
    ====================================
    <%@ page import="java.util.*" %>
    <%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
    <%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
    <html>
    <body>
       <%@ page import="RequestData" %>
       <jsp:useBean id="RD" class="RequestData" />
       <%Iterator data = (Iterator)request.getAttribute("Data");%>
       <logic:iterate id="element" name="RD" collection="<%=data%>">
          <jsp:getProperty name="RD" property="requestID" />
          <%=element%><br>
       </logic:iterate>
    </body>
    </html>
    And I have the RequestData.java file:
    ======================================
    private int requestID = 1234;
    public int getRequestID() { return requestID; }
    The jsp page display:
    ======================
    0 RequestData@590510
    0 RequestData@5b6d00
    0 RequestData@514f7f
    0 RequestData@3a5a9c
    0 RequestData@12d7ae
    0 RequestData@e1666
    Seems like the requestID is not returned. Does anybody know this?
    I have done the exact one using JSP and servlets, trying to learn using JSP and custom tags. The one with JSP and servlet looks like:
    ============================================
    <%@ page import="RequestData" %>
    <%Iterator data = (Iterator)request.getAttribute("Data");
    while (data.hasNext()) {
       RequestData RD = (RequestData)data.next();
       out.println(RD.getRequestID() );
    }%>

    Oh think I got it...
    but one thing I'm not sure is...
    If I use "<jsp:useBean id="RD" class="RequestData" />", do I still need "<%@ page import="RequestData" %>"?
    I tried without and it gives me error...

  • Help with this prefix method

    I need help with this method. The program runs but i still hava problem for example i enter +56 and return 11 but when i tried to enter -+567 return 25 instead of 23 also when i tried to enter +45-3 it return 9 so after 5 the program stop it just return the addition of 4+5
    public static int prefixEvaluation(String s){
      int result=0 ;
      int i=1;
      char ch = s.charAt(0);
      s=s.substring(i , s.length());// I want to be able to read all the character of the string every time i call the recursive method
      if (ch>='0'&& ch<='9'){
        result=((int)ch-48);
        System.out.println(result);
        return result;
      else if (ch=='+'|| ch=='-'|| ch=='*'|| ch=='/'){
        char op=ch;
        System.out.println(ch);
        int operand1= prefixEvaluation(s);
        s = s.substring(i++);
        int operand2= prefixEvaluation(s);

    double post!
    http://forum.java.sun.com/thread.jspa?threadID=781431&messageID=4444181#4444181

  • Help with JSP/Weblogic/Tomcat Discrepencies

    Hi,
              I have something very strange happening. I recently did some JSP stuff on
              WLS60SP1 and all went quite well. I then took those same JSP pages and tried
              them out on the latest release of TOMCAT. I was really impressed that
              everything seemed to be completely transparent and working just fine until
              the following situation:
              When I reference, within a JSP page, an object that has previously been
              added to the request scope that has just been created, but not messed with
              in anyway...meaning all the attributes in this bean have their default
              values set...and they are all Strings with the exception of one Integer
              using this format:
              <%= custVal.getCustomerNumber() %>
              - In WLS, what shows in the text field on the form is nothing, because
              customer number in the custVal object is null (default for a String)..this
              is what I want.
              - In Tomcat, what shows it the word "null".
              ...here is the weird part, by changing from scriptlet references to the
              <jsp:getProperty....> format such as....
              <jsp:getProperty name="custVal" property="customerNumber"/>
              -In WLS, he is still a happy camper and works just fine regardless of how I
              reference the bean
              -In Tomcat, I also get the correct results that I want.
              So, unlike most postings, I found out how to fix it but I would like to know
              why...any ideas?
              Thanks in advance,
              Paul Reed
              www.jacksonreed.com
              object training and mentoring
              Jackson-Reed, Inc. 888-598-8615
              www.jacksonreed.com
              Author of "Developing Applications with Visual Basic and UML"
              http://www.amazon.com/exec/obidos/ASIN/0201615797/jackreedinc/104-0083168-31
              95939
              Author of "Developing Applications with Java
              

              Try http://localhost:7001/HelloWorld.jsp
              "b. patel" <[email protected]> wrote:
              >
              >I need help with running a simple JSP. I created a WLS domain using the
              >WebLogic
              >Configuration Wizard. I am trying to access HelloWorld.jsp which is
              >located under
              >C:\bea\user_projects\wlsdomainex\applications\DefaultWebApp.
              >I type
              >http://localhost:7001/DefaultWebApp/HelloWorld.jsp. I get 404 - Page
              >Not Found
              >Error. The weblogic server starts Succesfully. I am trying this in Win
              >2K environment.
              >
              >I am new to WebLogic. Thanks for your Help in advance.
              >
              

  • URGENT help with JSP

    Any help with this will be really appreciated. I'm new to programming.
    If I search for an ssn in a database, I want to view all records relating to that ssn. However, I am getting all the records in the table.
    eg.
    at the prompt for ssn, let's say I enter 111111111
    I would like to see
    111111111 abc xyz etc
    111111111 pdg ppp etc
    however, I am getting
    000000000 utt tui etc
    111111111 tug etg etc
    How do I make limit the search to the ssn I want?
    The related code is below.
    Thanks.
    Java Code
    public void doGet(HttpServletRequest request,
    HttpServletResponse response)
    throws ServletException, IOException {
    if (checkLoginSessionPresent(request, response)) {
    loadTable("/esoladm/TaxView.jsp", request, response);
    else {
    checkLoginSessionRedirect("/esoladm/ESOLAdminMain.jsp", request, response);
    JSP Code
    <% while (MyTaxSuppress != null) { %>             
    <% String sPlanCode = MyTaxSuppress.getPlanCode(); %>
    <% String sSSN = MyTaxSuppress.getSSN(); %>
    <% String sTaxYear = MyTaxSuppress.getTaxYear(); %>
    <% String sDistCode = MyTaxSuppress.getDistCode(); %>
    <% double sGrAmount = MyTaxSuppress.getGrAmount(); %>
    <% String sStmtType = MyTaxSuppress.getStmtType(); %>
    <% boolean bNewSuppress = MyTaxSuppress.getNewSuppress(); %>
    <% String rowID = sPlanCode; %>
    <% rowID += sSSN; %>
    <% rowID += sTaxYear; %>
    <% rowID += sDistCode; %>
    <% rowID += sStmtType; %>
    <% rowID += sGrAmount; %>
    <% System.out.println( "Do While lp exiti" + rowID);%
    <% if (bNewSuppress) { %>
    <% out.println( "<TD> %>
    <% <img BORDER='0' SRC='/esoladm/ESOLNew2.gif' %>
    <% ALT='' WIDTH='50' HEIGHT='20'> </TD >"); %>
    <% } else { %>
    <% out.println( "<TD></TD>"); %>
    <% } %>
    <TD><%= sPlanCode %></TD>
    <TD><%= sSSN %></TD>
    <TD><%= sTaxYear %></TD>
    <TD><%= sDistCode %></TD>
    <TD><%= sGrAmount %></TD>
    <TD><%= sStmyType %></TD>
    <TD><input TYPE="checkbox" name="<%=rowID %>" ></TD>
    <% MyTaxSuppress = MySuppressTaxList.getNext(); %>
    <% } // end of while loop %>

    I don't see anywhere in your code where you conditionally output a tuple from your database. You seem to be outputting everything.
    Maybe you need:
    <% if (sSSN==input_value){ %>
    <TD><input TYPE="checkbox" name="<%=rowID %>" ></TD>
    <% } %>

  • Interface with a static method.

    I have tried to define an interface which requires a subclass to implement a static function.
    interface Testable {
    public static TestFrame getTestFrame();
    The idea is the the Testable object must be created with the appropriate constructer arguements, defined by the TestFrame. Thus the TestFrame must be created first.
    When I have tried this, the compiler complains that static is not allowed here.
    Is there a better way to do this?

    When I have tried this, the compiler complains that
    static is not allowed here.You can not have static methods in an interface - it would make no sense since static methods are not polymorphically overridden.
    >
    Is there a better way to do this?Since you need to know the class name in order to instantiate your object anyway, can't you just put the method in the class without it being part of the interface? - If the method is only necessary for object instantiation, then it doesn't sound like it belongs in an interface anyway - clients working with the interface type won't want to use it, so you're just cluttering up the interface.

  • Need some help with the String method

    Hello,
    I have been running a program for months now that I wrote that splits strings and evaluates the resulting split. I have a field only object (OrderDetail) that the values in the resulting array of strings from the split holds.Today, I was getting an array out of bounds exception on a split. I have not changed the code and from I can tell the structure of the message has not changed. The string is comma delimited. When I count the commas there are 26, which is expected, however, the split is not coming up with the same number.
    Here is the code I used and the counter I created to count the commas:
    public OrderDetail stringParse(String ord)
    OrderDetail returnOD = new OrderDetail();
    int commas = 0;
      for( int i=0; i < ord.length(); i++ )
        if(ord.charAt(i) == ',')
            commas++;
      String[] ordSplit = ord.split(",");
      System.out.println("delims: " + ordSplit.length + "  commas: " + commas + "  "+ ordSplit[0] + "  " + ordSplit[1] + "  " + ordSplit[2] + "  " + ordSplit[5]);
    The rest of the method just assigns values to fields OrderDetail returnOD.
    Here is the offending string (XXX's replace characters to hide private info)
    1096200000000242505,1079300000007578558,,,2013.10.01T23:58:49.515,,USD/JPY,Maker,XXX.XX,XXX.XXXXX,XXXXXXXXXXXXXXXX,USD,Sell,FillOrKill,400000.00,Request,,,97.7190000,,,,,1096200000000242505,,,
    For this particular string, ordSplit.length = 24 and commas = 26.
    Any help is appreciated. Thank you.

    Today, I was getting an array out of bounds exception on a split
    I don't see how that could happen with the 'split' method since it creates its own array.
    For this particular string, ordSplit.length = 24 and commas = 26.
    PERFECT! That is exactly what it should be!
    Look closely at the end of the sample string you posted and you will see that it has trailing empty strings at the end: '1096200000000242505,,,'
    Then if you read the Javadocs for the 'split' method you will find that those will NOT be included in the resulting array:
    http://docs.oracle.com/javase/6/docs/api/java/lang/String.html#split(java.lang.String)
    split
    public String[] split(String regex)
    Splits this string around matches of the given regular expression.  This method works as if by invoking the two-argument split method with the given expression and a limit argument of zero. Trailing empty strings are therefore not included in the resulting array.
    Just a hunch but your 'out of bounds exception' is likely due to your code assuming that there will be 26 entries in the array and there are really only 24.

  • I need help with this recursion method

         public boolean findTheExit(int row, int col) {
              char[][] array = this.getArray();
              boolean escaped = false;
              System.out.println("row" + " " + row + " " + "col" + " " + col);
              System.out.println(array[row][col]);
              System.out.println("escaped" + " " + escaped);
              if (possible(row, col)){
                   System.out.println("possible:" + " " + possible(row,col));
                   array[row][col] = '.';
              if (checkBorder(row, col)){
                   System.out.println("check border:" + " " + checkBorder(row,col));
                   escaped = true;
              else {
                    System.out.println();
                    escaped = findTheExit(row+1, col);
                    if (escaped == false)
                    escaped = findTheExit(row, col+1);
                    else if (escaped == false)
                    escaped = findTheExit(row-1, col);
                    else if (escaped == false)
                    escaped = findTheExit(row, col-1);
              if (escaped == true)
                   array[row][col] = 'O';
              return escaped;
         }I am having difficulties with this recursion method. What I wanted here is that when :
    if escaped = findTheExit(row+1, col);  I am having trouble with the following statement:
    A base case has been reached, escaped(false) is returned to RP1. The algorithm backtracks to the call where row = 2 and col = 1 and assigns false to escaped.
    How do I fix this code?
    I know what's wrong with my code now, even though that if
    if (possible(row, col))
    [/code[
    returns false then it will go to if (escaped == false)
                   escaped = findTheExit(row, col+1);
    how do I do this?

    Okay I think I got the problem here because I already consult with the instructor, he said that by my code now I am not updating my current array if I change one of the values in a specific row and column into '.' . How do I change this so that I can get an update array. He said to me to erase char[][] array = getArray and replace it with the array instance variable in my class. But I don't have an array instance variable in my class. Below is my full code:
    public class ObstacleCourse implements ObstacleCourseInterface {
         private String file = "";
         public ObstacleCourse(String filename) {
              file = filename;
         public boolean findTheExit(int row, int col) {
              boolean escaped = false;
              //System.out.println("row" + " " + row + " " + "col" + " " + col);
              //System.out.println(array[row][col]);
              //System.out.println("escaped" + " " + escaped);
              if (possible(row, col)){
                   //System.out.println("possible:" + " " + possible(row,col) + "\n");
                   array[row][col] = '.';
                   if (checkBorder(row, col)){
                   escaped = true;
                   else {
                    escaped = findTheExit(row+1, col);
                    if (escaped == false)
                    escaped = findTheExit(row, col+1);
                    else if (escaped == false)
                    escaped = findTheExit(row-1, col);
                    else if (escaped == false)
                    escaped = findTheExit(row, col-1);
              if (escaped == true)
                   array[row][col] = 'O';
              return escaped;
         public char[][] getArray() {
              char[][] result = null;
              try {
                   Scanner s = new Scanner(new File(file));
                   int row = 0;
                   int col = 0;
                   row = s.nextInt();
                   col = s.nextInt();
                   String x = "";
                   result = new char[row][col];
                   s.nextLine();
                   for (int i = 0; i < result.length; i++) {
                        x = s.nextLine();
                        for (int j = 0; j < result.length; j++) {
                             result[i][j] = x.charAt(j);
              } catch (Exception e) {
              return result;
         public int getStartColumn() {
              char[][] result = this.getArray();
              int columns = -1;
              for (int i = 0; i < result.length; i++) {
                   for (int j = 0; j < result[i].length; j++) {
                        if (result[i][j] == 'S')
                             columns = j;
              return columns;
         public int getStartRow() {
              char[][] result = this.getArray();
              int row = -1;
              for (int i = 0; i < result.length; i++) {
                   for (int j = 0; j < result[i].length; j++) {
                        if (result[i][j] == 'S')
                             row = i;
              return row;
         public boolean possible(int row, int col) {
              boolean result = false;
              char[][] array = this.getArray();
              if (array[row][col] != '+' && array[row][col] != '.')
                   result = true;
              return result;
         public String toString() {
              String result = "";
              try {
                   Scanner s = new Scanner(new File(file));
                   s.nextLine();
                   while (s.hasNextLine())
                        result += s.nextLine() + "\n";
              } catch (Exception e) {
              return result;
         public boolean checkBorder(int row, int col) {
              char[][] array = this.getArray();
              boolean result = false;
              int checkRow = 0;
              int checkColumns = 0;
              try {
                   Scanner s = new Scanner(new File(file));
                   checkRow = s.nextInt();
                   checkColumns = s.nextInt();
              } catch (Exception e) {
              if ((row + 1 == checkRow || col + 1 == checkColumns) && array[row][col] != '+')
                   result = true;
              return result;
    I thought that my problem would be not to read the file using the try and catch everytime in the method. How do I do this?? Do I have to create an array instance variable in my class?

  • Help with JSP Forward !!!

    I have 3 pages ...1) index.jsp 2) Forward.jsp 3) welcome.jsp
    I have 2 fields in the index.jsp once upon filling & hit submit it has to to go Forward.jsp page...in the Forward.jsp..i have coded only one tag with
    <jsp:forward page="welcome.jsp" />
    I have one question...once the page comes to Forward page...will it display the contents of the Welcome .jsp in the same page itself...or it will go to Welcome.jsp page..
    As i saw it will display the contents of Welcome.jsp page in itself...
    Please let me know...
    Regards
    Gnanesh

    I understand your question only because I have a set up totally identical to yours. The thread Matt suggested does explain the situation (i.e. the server passed control to another page but the client doesn't know that), but doesn't necessarily give a good solution a problem that you may have, and that I do have:
    If the user sees the welcome page, and for some reason decides to "reload", the forward page is re-executed, even though it has done its job. This could be a problem for session management if you specifically don't want that job being done twice in a session. Now you could hack around that, but I'd really rather see a neat solution. Is there one?

  • Need help with JSP - Session Bean scenario

    I have massive problems with a simple JSP <--> Statefull Session Bean scenario with Server Platform Edition 8.2 (build b06-fcs)
    What I do is generating a Collection in session bean returning it to JSP
    and giving the List back to Session Bean.
    A weird exception happens when giving the List back to Session Bean
    (see Exception details below)
    The same code runs without any trouble on Jboss Application Server 4.0.3
    Any help would be great!
    Please see code below
    Statefull Session Bean
    <code>
    package ejb;
    import data.Produkt;
    import java.util.ArrayList;
    import java.util.Collection;
    import java.util.Iterator;
    import javax.ejb.*;
    * This is the bean class for the WarenkorbBean enterprise bean.
    * Created 17.03.2006 09:53:25
    * @author Administrator
    public class WarenkorbBean implements SessionBean, WarenkorbRemoteBusiness, WarenkorbLocalBusiness {
    private SessionContext context;
    // <editor-fold defaultstate="collapsed" desc="EJB infrastructure methods. Click the + sign on the left to edit the code.">
    // TODO Add code to acquire and use other enterprise resources (DataSource, JMS, enterprise bean, Web services)
    // TODO Add business methods or web service operations
    * @see javax.ejb.SessionBean#setSessionContext(javax.ejb.SessionContext)
    public void setSessionContext(SessionContext aContext) {
    context = aContext;
    * @see javax.ejb.SessionBean#ejbActivate()
    public void ejbActivate() {
    * @see javax.ejb.SessionBean#ejbPassivate()
    public void ejbPassivate() {
    * @see javax.ejb.SessionBean#ejbRemove()
    public void ejbRemove() {
    // </editor-fold>
    * See section 7.10.3 of the EJB 2.0 specification
    * See section 7.11.3 of the EJB 2.1 specification
    public void ejbCreate() {
    // TODO implement ejbCreate if necessary, acquire resources
    // This method has access to the JNDI context so resource aquisition
    // spanning all methods can be performed here such as home interfaces
    // and data sources.
    // Add business logic below. (Right-click in editor and choose
    // "EJB Methods > Add Business Method" or "Web Service > Add Operation")
    public Collection erzeugeWarenkorb() {
    //TODO implement erzeugeWarenkorb
    ArrayList myList = new ArrayList();
    for (int i=0;i<10;i++)
    Produkt prod = new Produkt();
    prod.setID(i);
    prod.setName("Produkt"+i);
    myList.add(prod);
    return myList;
    public void leseWarenkorb(Collection Liste) {
    //TODO implement leseWarenkorb
    Iterator listIt = Liste.iterator();
    while(listIt.hasNext())
    Produkt p = (Produkt)listIt.next();
    System.out.println("Name des Produktes {0} "+p.getName());
    </code>
    <code>
    package data;
    import java.io.Serializable;
    * @author Administrator
    public class Produkt implements Serializable {
    private int ID;
    private String Name;
    /** Creates a new instance of Produkt */
    public Produkt() {
    public int getID() {
    return ID;
    public void setID(int ID) {
    this.ID = ID;
    public String getName() {
    return Name;
    public void setName(String Name) {
    this.Name = Name;
    </code>
    <code>
    <%@page contentType="text/html"%>
    <%@page pageEncoding="UTF-8"%>
    <%@page import="java.util.*"%>
    <%@page import="data.*"%>
    <%@page import="javax.naming.*"%>
    <%@page import="javax.rmi.PortableRemoteObject"%>
    <%@page import="ejb.*"%>
    <%--
    The taglib directive below imports the JSTL library. If you uncomment it,
    you must also add the JSTL library to the project. The Add Library... action
    on Libraries node in Projects view can be used to add the JSTL 1.1 library.
    --%>
    <%--
    <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
    --%>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>JSP Page</title>
    </head>
    <body>
    <h1>Online Shop Warenkorb Test</h1>
    <%--
    This example uses JSTL, uncomment the taglib directive above.
    To test, display the page like this: index.jsp?sayHello=true&name=Murphy
    --%>
    <%--
    <c:if test="${param.sayHello}">
    <!-- Let's welcome the user ${param.name} -->
    Hello ${param.name}!
    </c:if>
    --%>
    <%
    Context myEnv = null;
    WarenkorbRemote wr = null;
    // Context initialisation
    try
    myEnv = (Context)new javax.naming.InitialContext();
    /*Hashtable env = new Hashtable();
    env.put(Context.INITIAL_CONTEXT_FACTORY,"org.jnp.interfaces.NamingContextFactory");
    //env.put(Context.PROVIDER_URL, "jnp://wotan.activenet.at:1099");
    env.put(Context.PROVIDER_URL, "jnp://localhost:1099");
    env.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
    myEnv = new InitialContext(env);*/
    catch (Exception ex)
    System.err.println("Fehler beim initialisieren des Context: " + ex.getMessage());
    // now lets work
    try
    Object ref = myEnv.lookup("ejb/WarenkorbBean");
    //Object ref = myEnv.lookup("WarenkorbBean");
    WarenkorbRemoteHome warenkorbrhome = (WarenkorbRemoteHome)
    PortableRemoteObject.narrow(ref, WarenkorbRemoteHome.class);
    wr = warenkorbrhome.create();
    ArrayList myList = (ArrayList)wr.erzeugeWarenkorb();
    Iterator it = myList.iterator();
    while(it.hasNext())
    Produkt p = (Produkt)it.next();
    %>
    ProduktID: <%=p.getID()%><br></br>Produktbezeichnung:
    <%=p.getName()%><br></br><%
    wr.leseWarenkorb(myList);
    catch(Exception ex)
    %><p style="color:red">Onlineshop nicht erreichbar</p><%=ex.getMessage()%>
    <% }
    %>
    </body>
    </html>
    </code>
    the exception
    CORBA MARSHAL 1398079745 Maybe; nested exception is: org.omg.CORBA.MARSHAL: ----------BEGIN server-side stack trace---------- org.omg.CORBA.MARSHAL: vmcid: SUN minor code: 257 completed: Maybe at com.sun.corba.ee.impl.logging.ORBUtilSystemException.couldNotFindClass(ORBUtilSystemException.java:8101) at com.sun.corba.ee.impl.encoding.CDRInputStream_1_0.read_value(CDRInputStream_1_0.java:1013) at com.sun.corba.ee.impl.encoding.CDRInputStream_1_0.read_value(CDRInputStream_1_0.java:879) at com.sun.corba.ee.impl.encoding.CDRInputStream_1_0.read_abstract_interface(CDRInputStream_1_0.java:873) at com.sun.corba.ee.impl.encoding.CDRInputStream_1_0.read_abstract_interface(CDRInputStream_1_0.java:863) at com.sun.corba.ee.impl.encoding.CDRInputStream.read_abstract_interface(CDRInputStream.java:275) at com.sun.corba.ee.impl.io.IIOPInputStream.readObjectDelegate(IIOPInputStream.java:363) at com.sun.corba.ee.impl.io.IIOPInputStream.readObjectOverride(IIOPInputStream.java:526) at java.io.ObjectInputStream.readObject(ObjectInputStream.java:333) at java.util.ArrayList.readObject(ArrayList.java:591) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:585) at com.sun.corba.ee.impl.io.IIOPInputStream.invokeObjectReader(IIOPInputStream.java:1694) at com.sun.corba.ee.impl.io.IIOPInputStream.inputObject(IIOPInputStream.java:1212) at com.sun.corba.ee.impl.io.IIOPInputStream.simpleReadObject(IIOPInputStream.java:400) at com.sun.corba.ee.impl.io.ValueHandlerImpl.readValueInternal(ValueHandlerImpl.java:330) at com.sun.corba.ee.impl.io.ValueHandlerImpl.readValue(ValueHandlerImpl.java:296) at com.sun.corba.ee.impl.encoding.CDRInputStream_1_0.read_value(CDRInputStream_1_0.java:1034) at com.sun.corba.ee.impl.encoding.CDRInputStream.read_value(CDRInputStream.java:259) at com.sun.corba.ee.impl.presentation.rmi.DynamicMethodMarshallerImpl$14.read(DynamicMethodMarshallerImpl.java:333) at com.sun.corba.ee.impl.presentation.rmi.DynamicMethodMarshallerImpl.readArguments(DynamicMethodMarshallerImpl.java:393) at com.sun.corba.ee.impl.presentation.rmi.ReflectiveTie._invoke(ReflectiveTie.java:121) at com.sun.corba.ee.impl.protocol.CorbaServerRequestDispatcherImpl.dispatchToServant(CorbaServerRequestDispatcherImpl.java:648) at com.sun.corba.ee.impl.protocol.CorbaServerRequestDispatcherImpl.dispatch(CorbaServerRequestDispatcherImpl.java:192) at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleRequestRequest(CorbaMessageMediatorImpl.java:1709) at com.sun.corba.ee.impl.protocol.SharedCDRClientRequestDispatcherImpl.marshalingComplete(SharedCDRClientRequestDispatcherImpl.java:155) at com.sun.corba.ee.impl.protocol.CorbaClientDelegateImpl.invoke(CorbaClientDelegateImpl.java:184) at com.sun.corba.ee.impl.presentation.rmi.StubInvocationHandlerImpl.invoke(StubInvocationHandlerImpl.java:129) at com.sun.corba.ee.impl.presentation.rmi.StubInvocationHandlerImpl.invoke(StubInvocationHandlerImpl.java:150) at com.sun.corba.ee.impl.presentation.rmi.bcel.BCELStubBase.invoke(Unknown Source) at ejb._WarenkorbRemote_DynamicStub.leseWarenkorb(_WarenkorbRemote_DynamicStub.java) at org.apache.jsp.index_jsp._jspService(index_jsp.java:122) at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:105) at javax.servlet.http.HttpServlet.service(HttpServlet.java:860) at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:336) at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:297) at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:247) at javax.servlet.http.HttpServlet.service(HttpServlet.java:860) at sun.reflect.GeneratedMethodAccessor96.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:585) at org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:249) at java.security.AccessController.doPrivileged(Native Method) at javax.security.auth.Subject.doAsPrivileged(Subject.java:517) at org.apache.catalina.security.SecurityUtil.execute(SecurityUtil.java:282) at org.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.java:165) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:257) at org.apache.catalina.core.ApplicationFilterChain.access$000(ApplicationFilterChain.java:55) at org.apache.catalina.core.ApplicationFilterChain$1.run(ApplicationFilterChain.java:161) at java.security.AccessController.doPrivileged(Native Method) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:263) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:551) at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:225) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:173) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:551) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:551) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:132) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:551) at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:933) at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:189) at com.sun.enterprise.web.connector.grizzly.ProcessorTask.doProcess(ProcessorTask.java:604) at com.sun.enterprise.web.connector.grizzly.ProcessorTask.process(ProcessorTask.java:475) at com.sun.enterprise.web.connector.grizzly.ReadTask.executeProcessorTask(ReadTask.java:371) at com.sun.enterprise.web.connector.grizzly.ReadTask.doTask(ReadTask.java:264) at com.sun.enterprise.web.connector.grizzly.TaskBase.run(TaskBase.java:281) at com.sun.enterprise.web.connector.grizzly.WorkerThread.run(WorkerThread.java:83) Caused by: java.lang.ClassNotFoundException ... 69 more ----------END server-side stack trace---------- vmcid: SUN minor code: 257 completed: Maybe

    Hi,
    I have found a way out by passing the reference of my EJB in the HttpSession object and using it inside the javabean..

  • Help with creating a method within a class

    I need help creating another method within the same class.
    Here is part of my progam, and could anyone help me convert the switch statement into a seperate
    method within the same class?
    import javax.swing.JOptionPane;
    public class Yahtzee
         public static void main (String[] args)
              String numStr, playerStr, str, tobenamed;
              int num, times = 13, roll, x, y, maxRoll = 3, z = 0, t;
              int firstDie, secondDie, thirdDie, fourthDie, fifthDie, maxDie = 5, reroll;
              int rerolling = 0, categoryChoice, score, nextDie1, nextDie2, nextDie3, nextDie4;
              Die die1, die2, die3, die4, die5;
              do
              numStr = JOptionPane.showInputDialog ("Enter the number of player: ");
              num = Integer.parseInt(numStr);
              while (num < 1 || num > 6); //end of do loop
              String [] player = new String[num];
              // boolean //finsih later to make category choice only once.
              for (x = 0; x < num; x++)
                   playerStr = JOptionPane.showInputDialog ("Name of Player" + (x + 1) + " :");
                   player[x] = playerStr;  
              } //end of for loop
              die1 = new Die();
               die2 = new Die();
               die3 = new Die();
               die4 = new Die();
               die5 = new Die();
              int scoring [][] = new int [num][13];//scoring aray
              int[] numDie = new int[maxDie];
              String[][] usedCategory = new String [num][times];
              for (x=0; x < 13; x++)
                   for (y = 0; y < num; y++)
                      usedCategory[y][x] = " ";
              for (int choices = 0; choices < times; choices++)
                   //player turns for loop.
                   for (x = 0; x < num; x++)
                        //rolls the die;
                          for (y = 0; y < maxDie; y++)
                               numDie[y] =  die1.roll();
                     numStr = JOptionPane.showInputDialog (player[x] + "\n~~~~~~~~~~~~~~~~~~~~~~~"
                                                                            + "\nDie1: " + numDie[0]
                                                                                + "\nDie2: " + numDie[1]
                                                                                + "\nDie3: " + numDie[2]
                                                                                + "\nDie4: " + numDie[3]
                                                                                + "\nDie5: " + numDie[4]
                                                                                + "\nWhich dice do you want to reroll");
                    reroll = numStr.length();
                    if (reroll == 0)
                        t = maxRoll;
                   else{                                                      
                    //reroll
                         for(t = 0; t < maxRoll; t++ )
                             for (y = 0; y < reroll; y++)
                                    rerolling = numStr.charAt(y);
                                 //create another mwthod later.
                                    switch (rerolling)
                                         case '1':
                                              numDie[0] =  die1.roll();
                                              break;
                                         case '2':
                                              numDie[1] =  die1.roll();
                                              break;
                                         case '3':
                                              numDie[2] =  die1.roll();
                                              break;
                                         case '4':
                                              numDie[3] =  die1.roll();
                                              break;
                                         case '5':
                                              numDie[4] =  die1.roll();
                                              break;
                                         default:
                                         t = maxRoll;//to be changed
                                    } //end of switch class
                              }//end of reroll for loop
                                   JOptionPane.showMessegeDialog (player[x] + "\n~~~~~~~~~~~~~~~~~~~~~~~"
                                                                                      + "\nDie1: " + numDie[0]
                                                                                          + "\nDie2: " + numDie[1]
                                                                                          + "\nDie3: " + numDie[2]
                                                                                          + "\nDie4: " + numDie[3]
                                                                                          + "\nDie5: " + numDie[4]
                                                                                          + "\nWhich dice do you want to reroll"
                                               switch (rerolling)
                                         case '1':
                                              numDie[0] =  die1.roll();
                                              break;
                                         case '2':
                                              numDie[1] =  die1.roll();
                                              break;
                                         case '3':
                                              numDie[2] =  die1.roll();
                                              break;
                                         case '4':
                                              numDie[3] =  die1.roll();
                                              break;
                                         case '5':
                                              numDie[4] =  die1.roll();
                                              break;
                                         default:
                                         t = maxRoll; //not really anything yet, or is it?
                                    } //end of rerolling switch class
                                       //categorychoice = Integer.parseInt(category);
                              }//end of t for loop            
                   }//end of player for loop.

    samuraiexe wrote:
    well, i should have said it is a yahtzee program, and i ask the user what they want to reroll and whatever number they press, the switch will activate the case and the array that it will reroll.
    HOw would i pass it as an argument?You put it in the argument list. Modifying your original code a bit:
    public static void switchReroll (int[] dice, int position) {
         switch (position) {
         case '1':
                 dice[0] =  die1.roll()
                 break;
         case '2':
                 dice[1] =  die1.roll();
                 break;
         case '3':
                 dice[2] =  die1.roll();
                     break;
         case '4':
                 dice[3] =  die1.roll();
                 break;
         case '5':
                  dice[4] =  die1.roll();
                 break;
         default:
                 t = maxRoll;//to be changed
        } //end of switch
    }which you could then call as this:
    switchReroll(numDie, reroll);Note that your code still isn't done; the above won't compile. This is just an example of how you could pass the stuff as an argument (and note how the values have different names in the main method than in the switchReroll method -- this works, but also note that it's the same array of ints in both).
    By the way -- you really don't need a switch statement for this. You can do the same thing with a couple lines of code, which would lessen the advantage for a separate method. But I'd suggest continuing down this path, and then you could change the implementation of the method later.

Maybe you are looking for

  • How to use two gtx transceivers in one quad for two aurora ips

    hera mgt bank is 113 i am using two aurora ips 64b66b .for one ip GTX_X1Y0, another GTX_X1Y2.while simulating ,results are good.Coming to implementation its showing error in implementaion.that in MAP. Pack:2811 - Directed packing was unable to obey t

  • After installing IOS 6 on my iphone 4, why is my camera taking purple pictures?

    Immediately after installing IOS 6 on my iphone 4 on 9/22/12, when I attempt to use any of my phone apps, everything is colored in purple tint (see attached image). This includes taking video as well. If I flip the camera to the self facing camera, t

  • Tax code not working in PO

    Hi Experts, When i use a Tax code A1 in PO and clcik on Taxes it will not give me the respsective tax calculation. we have maintained the condition records for this. still it is not calcualting taxes can any one guide me how to deal with this regards

  • JCE Verifier - a bug in the Java Docs?

    When implementing a new JCE Provider, one should follow the special docs, such as http://java.sun.com/j2se/1.4.2/docs/guide/security/jce/HowToImplAJCEProvider.html In the section "Creating a JarFile Referring to the JAR File", there's this code snipp

  • Holo Launcher is awesome if you want to feel like you have ICS

    I installed this launcher ( https://play.google.com/store/apps/details?id=com.mobint.hololauncher&feature=nav_result#?t=W251bGwsMSwyLDNd ) on my Casio Commando and I love it. Keep in mind I also have a Galaxy Nexus so I have real ICS but putting on a