Results 1 to 12 of 12
  1. #1
    Nicholas Jordan's Avatar
    Nicholas Jordan is offline Senior Member
    Join Date
    Jun 2008
    Location
    Southwest
    Posts
    1,018
    Rep Power
    8

    Default [SOLVED] base directory for servlets

    I spent half a day getting a temp placeholder servlet to compile. Let alone whether it will run or not, I put it in /home/******/webapps/ROOT/WEB-INF/classes

    Is this correct?
    Introduction to Programming Using Java.
    Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor

  2. #2
    fishtoprecords's Avatar
    fishtoprecords is offline Senior Member
    Join Date
    Jun 2008
    Posts
    571
    Rep Power
    7

    Default

    This is one of the reasons I use NetBeans. It makes a .jar or .war, you just put it where Tomcat wants, and a miracle happens.

    The whole jar, .ear, .war stuff drives me crazy. Its different, sort of, but not really. I can't ever remember where anything goes from one thing to another.

  3. #3
    Nicholas Jordan's Avatar
    Nicholas Jordan is offline Senior Member
    Join Date
    Jun 2008
    Location
    Southwest
    Posts
    1,018
    Rep Power
    8

    Default crazy drivers

    Short version:
    One has to put /servlet/ in the url or do an xml mapping.

    Longer version:
    I have to get up on the front burner on xml due to a need for it.

    As for the drivers ( here ) I had to go back and get the NetBeans that had the Web stuff. When I ran the installer it refused to overwite the previous install even though I wanted it to. In so doing, I had to obtain a random port for admin port for one of the servers. I already had a utility written. I know you will say something because I did not use java.security.SecureRandom, but this is dramatically better than fingers-pounding-keyboard or guess or accepting what is in the setup and install script:
    Java Code:
    import java.util.Random;//
    import java.net.*;//
    
    /* USE OF THIS CODE CONSTITUTES DISCUSSION OF OPINION IN A TECHNICAL FORUM
     * NO SUITABILITY FOR ANY USE IS IMPLIED BY READING THE OPINION PROVIDED.
     * 
     * Reader assumes the risk of any use.
     *
     * Simple client/server Socket selection program.
     *
     * The Dynamic and/or Private Ports are those from 49152 through 65535
     * Source:  http://www.iana.org/assignments/port-numbers
     * The port numbers are divided into three ranges: the Well Known Ports,
     * the Registered Ports, and the Dynamic and/or Private Ports.
     */
    
    public class PortSelector extends Socket
    {
        private static final Object lock = new Object();
    
        int port;//
        // Private Ports are those from 49152 through 65535
        static final int range = ( 65535 - 49152 );
        InetAddress iwannaBanna;//
        public static Socket sockitToEm;//
        /***************** always put some random stings in your code *****************/
        /***************** it's more fun that way and makes peole think *****************/
        /***************** you know what your are doing.    *****************/
        java.lang.String a = "06d98abff66495089d23f269cf296b783f5499e8b1b75fabc97e417f5319ba2f";
        java.lang.String b = "fffb0d5f946240499dd413202c8567f070d32672ece45f75249164ece47b2c3e";
        java.lang.String c = "7b29d40b262212abea99171af1c197835297c17a7361f2a5b371a8146f8340c3";
        java.lang.String d = "3657e092450b24d7f3542df00daa7f4a445dbd2baa7064f2bbdd165a7ad16b58";
        PortSelector()  //
        {
            // Extensible
            super();//
        }
        //
        public static synchronized Integer getPortNumber()
        {
            Random candidateInt = new Random();//
            port = (candidateInt.nextInt(49152) + range);
            if((port < 49152) || (port > 65535))
            {
                cadidatePort = (candidateInt.nextInt(49152) + range);
            }
            while((port < 49152) || (port > 65535));
            return new Integer(port);
        }
        //
        public static void main(String[] args)
        {
            System.out.println(new PortSelector().getPortNumber().toString());//
        }
    
     }
    Introduction to Programming Using Java.
    Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,800
    Rep Power
    25

    Default

    Looking at this code, I didnt' think it would compile because of port being non static. I tried it and it didn't.
    Why the new if the methods are static?
    new PortSelector().getPortNumber().toString());//

  5. #5
    fishtoprecords's Avatar
    fishtoprecords is offline Senior Member
    Join Date
    Jun 2008
    Posts
    571
    Rep Power
    7

    Default

    Quote Originally Posted by Nicholas Jordan View Post
    Short version:
    One has to put /servlet/ in the url or do an xml mapping.
    Yeah, you have to glue your code in, servletmapping in the XML files is where I usually do it. I tend to forget these little details, as I tend to not have a lot of serlet entry points, and netbeans will add them properly for me with you do the new -> servlet generator

  6. #6
    Nicholas Jordan's Avatar
    Nicholas Jordan is offline Senior Member
    Join Date
    Jun 2008
    Location
    Southwest
    Posts
    1,018
    Rep Power
    8

    Default processRequest

    I cannot see all of your reply, fishtop, but yes@details always seems to fishtail.

    Mangaged to get up in NetBeans with Web and pasted my previous sources directly into a base jsp with only one ( so far ) issue in hundreds of lines. An ommited list element in a font tag. I consistently get the mental visual of an elephant. { basically the same one I mentioned earlier }

    I have got a base page with
    Java Code:
    <form action="TemporaryOrderForm" method="post">
    coded in for protoyping and development all ready, so I just use that a drop-in as soon as I can get template servlet code from the IDE. What I need to do here is establish whether this processRequest method ( which it came up with for template code ) is called by doPost behind the scenes. I chose Tomcat during the install, that's what the commercial server uses. I have code written - ready for testing - already in doPost with some logic to write a base page if several form fields do not come in. Something along the lines of
    Java Code:
    <form action=testServlet><input type="hidden" value="( semi-random string )"
    If this and two or three other parameters are non-null and match up here and there, we go to the SecureRandom store and get a sessionID as well as pull one from the Server and all I am doing is playing with kittens.

    Paranoia not only strikes deep, it as well has inversions. If the user-agent does not make it past those, this processRequest method as they have it is the approach of choice. I have the code, ready to drop in it, provided I can make is so that we either do processRequest or doPost but not both.
    Introduction to Programming Using Java.
    Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor

  7. #7
    Nicholas Jordan's Avatar
    Nicholas Jordan is offline Senior Member
    Join Date
    Jun 2008
    Location
    Southwest
    Posts
    1,018
    Rep Power
    8

    Default looks stupid, works great.

    Quote Originally Posted by Norm View Post
    Looking at this code, I didnt' think it would compile because of port being non static. I tried it and it didn't.
    you need to get a better compiler. Tool Output:
    Tool completed successfully

    Here, hava a port number: 56674

    Why the new if the methods are static?
    new calls PortSelector() which we say that constructors do not return anything, but new 'returns' a PortSelector 'object' on which we may then call the method '"getPortNumber()" which retuns an Integer from the java base libraries, on which we call .toString directly in the print statement in main.

    Spending time on code correctness while I had an installer open would have been premature optimization. I have much stronger words, mabye I better have some of your beer. Got wheat beers? Medium body, medium everything all the way through.
    Introduction to Programming Using Java.
    Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor

  8. #8
    Nicholas Jordan's Avatar
    Nicholas Jordan is offline Senior Member
    Join Date
    Jun 2008
    Location
    Southwest
    Posts
    1,018
    Rep Power
    8

    Default How's this for glue?

    I got a full build with one placement of a semi-colon statement terminator. I tried to save the build log so that you could look at it but I have an OO failure, clear and present:
    Java Code:
    http://localhost:8084/Kochi/TemporaryOrderForm
    Kitty and Kochi map to the same thing.

    Sort of a cute moment, the real world likes that.

    Pretty good for one of those code-bloated IDE's.
    Introduction to Programming Using Java.
    Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor

  9. #9
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,800
    Rep Power
    25

    Default

    This compiles and executes:
    Java Code:
    PortSelector.getPortNumber().toString()
    static methods don't require an object
    port not being static can't be referenced from a static method

    Besides the fact that:
    Java Code:
      while((port < 49152) || (port > 65535));
    will loop forever it port is out of range?

    Am I looking at the same code as you are?
    Why post code with so many errors?


    My beers were/will be British ales.

  10. #10
    Nicholas Jordan's Avatar
    Nicholas Jordan is offline Senior Member
    Join Date
    Jun 2008
    Location
    Southwest
    Posts
    1,018
    Rep Power
    8

    Default well, yes .....

    Quote Originally Posted by Norm View Post
    This compiles and executes:
    Java Code:
    PortSelector.getPortNumber().toString()
    static methods don't require an object
    port not being static can't be referenced from a static method.
    Well, yes, I could have called getPortNumber() directly from main() ~ I was in a hurry. It did run, I did get a port number. The fact that I went through a call to new sort of blurs our discussion, yes but even with an object:

    PortSelector portSelector = new PortSelector();

    I can still call getPortNumber on portSelector. It is a matter of a few instructions to access a variable sized memory allocation called the heap. An early form of failure in programs called stack crash was when the heap would grow so big as to overrun the physical addresses where the running program stacks things up.

    Because I was using Java, I could just code something to get a random port number and prototype not worrying about matters like that. If it failed, I just get an Exception and main() returns control to the JVM without breaking my machine.


    Quote Originally Posted by Norm View Post
    Besides the fact that: while((port < 49152) || (port > 65535)); will loop forever it port is out of range?
    This method of searching is extremely powerful when the size of the dataset vastly exceeds the search window available. We have a call to next random in there somewhere, if not you have a valid point. These rarely go past a few milliseconds to get something in range. You can try narrowing the window but I promise up front on the board that no book you can find will ever tell you how to sit on the keyboard without trapping a Thread in a while() loop. While loops consume processor power, power that is needed if we are to keep the machine responsive. A good exercise would be to put a ++int if int greater than loop limit, discard request and report failure to System.out

    I coded something that sits on the keyboard to watch for keystrokes but consumes almost no processor power. Good exercise for you. Work on it, post in beginner and read Algorighms in Java by Sedgewick. Really effective tool for someone with your skill level.

    In fact, one could focus the search window on some specific area of the dataset by using a next Gaussian method already available in the libraries. Tell ya what, Bocephus, center my search on the desired range using a next Gaussian. While you are sitting there in an all night hair puller be sure to Amazon a copy of Sedgwick's masterwork. Some of the techiques in Cave Oriented Bloated Oh Languge can be prototyped in Java very effectively using the cited work. Doing so will prevent moderators watching me suffer your unresearched stumbling.

    ( Pro's here folks, don't worry about it )

    Am I looking at the same code as you are?
    Probably, but I think you need to look a little closer.

    Why post code with so many errors?
    What error, where? Here, hava port number:
    Java Code:
    62060
    I think it is in hexadecimal ~ that was the first toString I found in the sources. Help me here, boss -> did I call toHexString(int i) or call toString(int i)

    My beers were/will be British ales.
    Those tend to be too stout and bitter for me. I need a moderately smooth Lager.
    Introduction to Programming Using Java.
    Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor

  11. #11
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,800
    Rep Power
    25

    Default

    Running: C:\Program Files\Java\jdk1.5.0_04\bin\javac.exe -deprecation -g -Xlint PortSelector.java

    PortSelector.java:42: non-static variable port cannot be referenced from a static context
    port = (candidateInt.nextInt(49152) + range);
    ^
    PortSelector.java:43: non-static variable port cannot be referenced from a static context
    if((port < 49152) || (port > 65535))
    ^
    PortSelector.java:43: non-static variable port cannot be referenced from a static context
    if((port < 49152) || (port > 65535))
    ^
    PortSelector.java:45: cannot find symbol
    symbol : variable cadidatePort
    location: class PortSelector
    cadidatePort = (candidateInt.nextInt(49152) + range);
    ^
    PortSelector.java:47: non-static variable port cannot be referenced from a static context
    while((port < 49152) || (port > 65535));
    ^
    PortSelector.java:47: non-static variable port cannot be referenced from a static context
    while((port < 49152) || (port > 65535));
    ^
    PortSelector.java:48: non-static variable port cannot be referenced from a static context
    return new Integer(port);
    ^
    7 errors

    7 error(s)
    I guess I need a better compiler. Mine is too literal. It needs to figure out what the coder entended and fix it.

    Where does port get changed in the while statement?
    while((port < 49152) || (port > 65535));
    It appears to be a standalone while, not part of a do{}

  12. #12
    Nicholas Jordan's Avatar
    Nicholas Jordan is offline Senior Member
    Join Date
    Jun 2008
    Location
    Southwest
    Posts
    1,018
    Rep Power
    8

    Default try this

    Java Code:
    import java.net.URL;
    
    public class EatHumblePie
    {
        private static String Earl =
        "http://www.highgravitybrew.com/productcart/pc/configurePrd.asp?idProduct=2546";//
        // Member function of Class EatHumblePie
        public static synchronized Integer getPortNumber()
        {
            // Standard Library call.
            Random candidateInt = new Random();//
            // Get first int value, should be in range of 49152 to 65535
            int candidatePort = (candidateInt.nextInt(49152) + range);
            // If candidate port is not between those values, like if
            // I blundered the previous line....
            if((candidatePort < 49152) || (candidatePort > 65535))
            {
                // Then 
                do
                {
                    candidatePort = (candidateInt.nextInt(49152) + range);
                }
                while((candidatePort < 49152) || (candidatePort > 65535));
            }
            else
            {
                // ....
                URL earl = new URL(Earl);
            }        
            return new Integer(candidatePort);
        }
        //
        public static void main(String[] args)
        {
            // Default constructor from compiler
            EatHumblePie ehp = new EatHumblePie();
            // Get an integer from static context
            Integer SelectedPort = EatHumblePie.getPortNumber();
            // Print the integer to the console.
            System.out.println(SelectedPort.toString());//
        }
    
    }
    This is near trivial compared to getting one of those IDE's to go in the same general direction as the intent the project was designed for. To answer your central question the nextInt(int value) gives us an integer between zero and the value passed in the function call. Admittedly I was running a previous build, the code I put up was done in dire straits. I would not have done that with any other programming tool. Finding all this stuff in a project can become involved, all the details have to be carefully preened again and again.

    I sort of thought it trivial to recognize the do loop and the if and how the thing works overall. The do loop as I have it now will likely never be reached, but it is a standard engineering line of code that returns a number between two values. It sort of reverses.

    UpperBound - LowerBound == Range.
    Integer anInteger = Random.nextInt(Range) + LowerBound;

    That is around the level when I went in Second grade and they told me how to spell Apple on the first day of class. Can beer be made from Apples? Sorry if I wasted any of your time, I sort of get acclimatized to expecting everyone can see what I intended. Try reading an RFC in thirty minutes and getting a fundamental grasp of a subject you have never worked on before in that fast-paced environment. that is what took me away from going back and editing the code.

    EDIT:
    Marty, I am trying to do some super fragilistics - can we edit and delete my earlier poor code? I sort of see all conditionals as a branch and just rue the day they made goto goaway.
    Last edited by Nicholas Jordan; 07-05-2008 at 02:48 PM. Reason: poor code in earlier post

Similar Threads

  1. servlets or jsp
    By krishnapal in forum Advanced Java
    Replies: 1
    Last Post: 12-13-2007, 03:31 PM
  2. Problems with Jtable connected to data base
    By elizabeth in forum AWT / Swing
    Replies: 2
    Last Post: 08-07-2007, 05:24 PM
  3. Replies: 1
    Last Post: 08-06-2007, 06:38 PM
  4. 2 threads sharing a data base connection
    By Ed in forum Advanced Java
    Replies: 2
    Last Post: 07-04-2007, 05:41 AM
  5. Connection to data base
    By Daniel in forum JDBC
    Replies: 2
    Last Post: 06-07-2007, 05:55 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •