Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Internet programming...

  • 28-01-2002 1:36pm
    #1
    Posts: 0


    Hey folks,
    Could anyone explain to me please, what exactly a servlet is?
    what's the difference between a servlet and a server?

    Also, i read that cgi programming can be done in any langugage, does that mean that Java could be a suitable language for such interactivity or is perl usually the best one to use?

    I'm trying to get into online programming and interactivity with web pages.

    Thanks in advance for the help


Comments

  • Closed Accounts Posts: 1,651 ✭✭✭Enygma


    Hi MoonHawk,

    A servlet is just a java program that spits out a HTTP header and HTML. It runs inside a servlet container like Tomcat (http://jakarta.apache.org/tomcat) which would be the server.
    JSP is a type of Java Servlet but it's better suited for display, whereas a servlet is better suited for processing. A JSP is just like a PHP or ASP page, you can embed Java code inside your HTML.
    A JSP page is in face turned into a servlet before it's compiled but it's a lot easier to embed Java in HTML than it is to write HTML with out.println()'s.


    Perl is always associated with CGI programming but any language that can process text is suitable. Perl was the best choice for CGI programming for a long time but now there are other options like PHP, ASP and JSP.

    If you already know Java then I'd advise you to go download Tomcat and start playing with JSPs and servlets. They're really both quite easy. If you don't know Java then PHP is probably the best option as it's one of the more popular languages used for web programming.


  • Registered Users, Registered Users 2 Posts: 15,443 ✭✭✭✭bonkey


    Originally posted by MoonHawk
    Hey folks,
    Could anyone explain to me please, what exactly a servlet is?
    what's the difference between a servlet and a server?

    I'm sure there are more qualified descriptions out there, but effectively a "servlet" is a program which runs on the server, typically providing a discrete set of functionality, extended from the server itself. It is not a standalone program as it is tied inextriacablty to the running of the web-server.

    Also, i read that cgi programming can be done in any langugage, does that mean that Java could be a suitable language for such interactivity or is perl usually the best one to use?

    In theory, you could use any language for cgi programming. Java is a valid option, but one you wont see used much. Why? Simple - because cgi programming is only one way of interacting with the server, and Java is more suited to using other methods of interaction (such as via JSP).

    I'm trying to get into online programming and interactivity with web pages.
    Without more information, its hard to recommend one approach over another. In truth, there is very little to choose between most of the major approaches other than personal preference, and maybe suitability for a specific task.

    jc


  • Closed Accounts Posts: 1,651 ✭✭✭Enygma


    In theory, you could use any language for cgi programming. Java is a valid option, but one you wont see used much. Why? Simple - because cgi programming is only one way of interacting with the server, and Java is more suited to using other methods of interaction (such as via JSP).

    Isn't a servlet a CGI program?


  • Closed Accounts Posts: 1,322 ✭✭✭phobos


    An example of a web application (programmed using CGI/Servlets/JSP/PHP etc) could be the Boards.ie website itself. You are frequently presented with HTML forms, in which you fill out and submit. Have you ever wondered what happens that information you submit, and what happens to it?. Well that's where Servlets/JSPs.... come in!.

    Web applications are used to generate dynamic content, such as reading info from a database and then formatting it as HTML output, which can be rendered on your web browser. To your browser (such as IE/Netscape) the output is the same as if it was a standard *.htm/*.html document. Once it output leaves the server it's all just HTML/client based scripts.

    A this point I think everything has been mentioned by Bonkey & Enygma ;)

    ;-phobos-)


  • Closed Accounts Posts: 1,295 ✭✭✭Meh


    Originally posted by Enygma
    Isn't a servlet a CGI program?
    No. Neither are PHP, ASP or JSP.
    CGI = Common Gateway Interface. An obsolete method of web programming, where the web server starts up a new process for every new request that comes in (very inefficient). If someone suggests you use CGI for a web project, fire them. With servlets written in Java, a Java server process listens for incoming requests and uses an existing thread from a pool of idle threads to handle each request (much more efficient).
    You could in theory use Java for CGI programming, but you would be insane to do so, with the entire JVM having to be loaded for every incoming request.


  • Advertisement
  • Closed Accounts Posts: 1,651 ✭✭✭Enygma


    Ahhh, my idea of a CGI program was a *something* that ran on the webserver and spat out HTML. :rolleyes:
    Thanks for clearing that up :)


  • Banned (with Prison Access) Posts: 16,659 ✭✭✭✭dahamsta


    Isn't a servlet a CGI program?

    No. It's also important to point out that PHP isn't necessarily a CGI program either, although it can be run as one. Webopedia will probably explain it all far better than I could:

    http://www.webopedia.com/TERM/s/servlet.html
    http://www.webopedia.com/TERM/C/CGI.html
    http://www.webopedia.com/TERM/P/PHP.html
    http://www.webopedia.com/TERM/J/JSP.html
    http://www.webopedia.com/TERM/A/Active_Server_Pages.html

    adam


  • Registered Users, Registered Users 2 Posts: 2,660 ✭✭✭Baz_


    wow, thanks for that info meh, of course it has completely changed my whole plan for my website setting me back some time, but it is very good to know non-the-less.


  • Posts: 0 [Deleted User]


    Thanks for the replies all,

    I was playing around various different programming thingys today, I was learning how to graphically program in Java (learning how to make JFrames and things like that...hardest thing is to remember all the different constructors and all that) and also, I was playing around with raw HTML (not real programming i know but still good to know), I want to get to know how to do good pages.

    I read up an JSP and servlets and all that, and although some of you may say that it's inefficient, I think that , for learning purposes, I'll just expand my java knowledge and stick with that for a while, just to get into it, as, up until now, I found the idea of CGI kinda abstract but it's making more and more sense.

    it's great trying to experiment with different ideas, so i'll mess around with a few things...for now , i'll look at other cgi's and see how they're implemented.

    thanks for the help all!


  • Registered Users, Registered Users 2 Posts: 21,264 ✭✭✭✭Hobbes


    In theory, you could use any language for cgi programming. Java is a valid option, but one you wont see used much.

    Erm, CGI programming afaik is different to servlets. Java Servlets have better load balancing then CGI (doesn't spawn multiple servlets for multiple users), and is starting to become the preferred way because of it.


  • Advertisement
  • Closed Accounts Posts: 1,651 ✭✭✭Enygma


    MoonHawk, no ones saying that JSP's and servlets are inneficient. The confusion arose when I asked if they're the same thing as CGI which they're not.

    JSP's can be highly efficient and can, if done properly decrease development time too. Go get yourself a copy of Tomcat (http://jakarta.apache.org) or Resin (http://www.caucho.com) and play around with JSP's.

    Some good sites worth visiting regularly are:
    http://www.onjava.com
    http://developer.java.sun.com
    http://www.ijug.org
    http://www.javaworld.com
    http://www.serverpages.com

    Good Luck


  • Registered Users, Registered Users 2 Posts: 21,264 ✭✭✭✭Hobbes


    Mentioned in another thread... Forte 3.0 (free from java.sun.com ) comes with Tomcat built in.

    Just download that. :)


  • Registered Users, Registered Users 2 Posts: 16,414 ✭✭✭✭Trojan


    Does nobody do any real programming any more?

    *sigh*

    Al.


  • Registered Users, Registered Users 2 Posts: 21,264 ✭✭✭✭Hobbes


    What is real programming? (punchcards?)


  • Closed Accounts Posts: 1,651 ✭✭✭Enygma


    I always thought it was the type of programming that made you a better person :p


  • Registered Users, Registered Users 2 Posts: 16,414 ✭✭✭✭Trojan


    Originally posted by Hobbes
    What is real programming? (punchcards?)

    I think we've moved on from that :)

    Al.
    Even Unix might not be as bad on Real Programmers as it once was. The latest release of Unix has the potential of an operating system worthy of any Real Programmer-- two different and subtly incompatible user interfaces, an arcane and complicated teletype driver, virtual memory. If you ignore the fact that it's "structured", even 'C' programming can be appreciated by the Real Programmer: after all, there's no type checking, variable names are seven (ten? eight?) characters long, and the added bonus of the Pointer data type is thrown in-- like having the best parts of Fortran and assembly language in one place. (Not to mention some of the more creative uses for #define.)


  • Registered Users, Registered Users 2 Posts: 15,443 ✭✭✭✭bonkey


    Originally posted by Meh
    If someone suggests you use CGI for a web project, fire them.

    This is quite possibly the most intelligent evaluation of CGI performance I've ever heard. Its so good, I'm going to steal it and use it in future :)

    jc


  • Posts: 0 [Deleted User]


    Does anyone feel that, nowadays, programming has become more and more "trendy" and,as such, new languages are coming out which are easier and easier to learn, meaning that less and less things can be done through the language?

    Example:
    Assembly Language Programming...hard to learn, hard to construct great programs in, but great to know when you're well with it.

    But new higher level programming languages seem to be hiding more of the behind the scenes stuff to the programmer because the "nu-programmer" just wants to do cool stuff, rather than understand the computer and the workings of it.

    I personally have no experience with something like C#, but that's the impression i get from languages such as that.

    I love using Java, i think it's great that amazing things are possible with it, but I can't help feeling like we're missing out on something with these new languages...any one feel the same?
    :confused:


  • Closed Accounts Posts: 1,651 ✭✭✭Enygma


    I know what you mean, but to be honest, most of the time I'd rather get things done than mess about with memory allocation and stacks etc.

    Is there anything wrong with that? Hardly.

    Of course newer languages are going to hide the details from you, it allows you to get the job done quickly and easily. If they didn't, they wouldn't be successful.

    Would you prefer a world without Java or C# or any of the other newer languages? Would you rather everyone had to write applications in assembly or FORTRAN?

    But new higher level programming languages seem to be hiding more of the behind the scenes stuff to the programmer because the "nu-programmer" just wants to do cool stuff, rather than understand the computer and the workings of it.

    Same way people drive their cars everyday without understanding the engine, and the same way people use their computers every day without understanding how it works, and the same way people watch TV without understanding how that works.


    A programming language that makes something easy isn't necessarily a bad thing, VB makes GUI programming easy, Perl is great for processing text, Java makes it easy to port to other architectures.


    Personally I'd rather not know every little detail about my machine, I'd rather get the job done.
    There's no room for an elitist attitude when it comes to nailing a deadline.


  • Posts: 0 [Deleted User]


    Yeah I can see your point alright, it's just my idea of programming used to be this notion of some genius who knew it all (almost all the languages).

    Now I know that it's impossible to know everything, I'd just like to know one thing well if you know what I mean, rather than do a bit of it and then leave it...maybe that's what I was getting at (i'm confusing myself!)

    eg. I'd hate to learn a bit of c++ and then leave it, to do something in another language (if i had to)...i'd be the type to finish what i was learning and then move on.


    But I've found out that it's not the way to do things...there's just not time to get everything done like that.

    :confused: My head hurts now! :p


  • Advertisement
  • Closed Accounts Posts: 1,651 ✭✭✭Enygma


    Just learn what you need to learn when you need to learn it, in five years time you'll look back and be amazed, and in ten years and twenty...

    dont' stop learning in other words :)


  • Registered Users, Registered Users 2 Posts: 258 ✭✭peterd


    Does anyone feel that, nowadays, programming has become more and more "trendy" and,as such, new languages are coming out which are easier and easier to learn, meaning that less and less things can be done through the language?

    An example of this is could be Escapade (http://escapade.portland.co.uk/). It's like dummy programming for dummies! I've never used it, but from a quick read over the site, it's just using a template file and inserting text. It was first 'trendy' to have your own web site once sites came out with simple DIY tools and free webspace. Now everyone can be a programmer.

    [edit] wrong url


  • Banned (with Prison Access) Posts: 16,659 ✭✭✭✭dahamsta


    Does anyone feel that, nowadays, programming has become more and more "trendy" and,as such, new languages are coming out which are easier and easier to learn, meaning that less and less things can be done through the language?

    Depends on your definition of a language really. Taking PHP as an example, I don't really define it as a programming language - more a scripting language - but it has to be said that it does what it was designed to do particularly well, it has an enormous API that offers a multitude of options, and it's relatively simple to use. Granted, it is a wee bit "trendy", but it does bring down barriers of entry to the field, which has to be a good thing IMHO. It has its downside too, in that you get a lot of dorks asking stupid questions, but most of these either turn into clever coders or just fade away. It has to be said that PHPBuilder was a heck of a lot more fun when PHP was less popular though. Now it's a waste of effort.

    adam


  • Posts: 0 [Deleted User]


    Yeah dahamsta, it's great that more and more programmers are coming into it, there's always someone who has a good idea, the hard part is turning it into a program.

    I find another example of such a tool is Borland JBuilder, which draws your applications and all that, which is cool (i can't imagine designing and drawing every application layout by plain code all the time!) but at the same time,when it comes to debugging, you don't know where or what the methods that the program has put in and you get lost because it's not your code.
    Things like that get to me, it feels like i'm not doing work with it at all and just getting frustrated.

    peterd, following your point, I remember seeing about 4/5 years ago webpages done by people for a laugh, nowadays almost everything incorporates cgi in some form.

    And enygma, i'll take that advice on board, it makes sense to keep learning , adding bits and pieces on to what i know eventually...if i try and do it all at once, i won't be able to and give up.


  • Registered Users, Registered Users 2 Posts: 16,414 ✭✭✭✭Trojan


    ok, so before you tell me, I know I started it.

    That said, I agree with Enygmas practical attitude:
    Originally posted by Enygma

    Personally I'd rather not know every little detail about my machine, I'd rather get the job done.
    There's no room for an elitist attitude when it comes to nailing a deadline.

    But there is room for an elitist attitude when you're in the pub with your Java/C#/html-loving mates, and there is room for an elitist attitude when you're slagging on a BBS :)

    Originally posted by MoonHawk

    I can't help feeling like we're missing out on something with these new languages...any one feel the same?

    Yep, that's why I'm doing system level programming, always have. Much nicer to be mucking about below the application level.
    Originally posted by MoonHawk

    it's just my idea of programming used to be this notion of some genius who knew it all (almost all the languages).

    You must be joking :)
    Check out yahoo.

    Al.


  • Posts: 0 [Deleted User]


    Trojan,
    is that system level programming just assembly programming?

    Assembly is something i'd like to get into (not now but in time, after everything else is done), as it is FAST for simple I/O programs.
    I like it.

    is C# any good or is it another type of hybrid language hacked together?

    and what's this about slagging on a bbs? ;-)


  • Closed Accounts Posts: 1,295 ✭✭✭Meh


    Originally posted by MoonHawk
    Assembly is something i'd like to get into (not now but in time, after everything else is done), as it is FAST for simple I/O programs.
    I like it.
    "Assembly code is fast" is probably the greatest programming myth there is. Sure, back in the old days with non-optimizing compilers, it was possible to squeeze a bit more performance out of your 4 MHZ 68000 using assembly code. But these days, with pipelining, speculative execution, caching and branch prediction, compilers do a much better job of optimizing code than any human could do. Instruction scheduling, cache line alignment etc are all simple mechanical processes that are better done by compilers than by programmers.


  • Posts: 0 [Deleted User]


    Ah right
    well maybe that's the case, that in today's world and fast processors, we don't need assembly...but it's handy to know because you will understand better what the compiler is doing...sure it may be becoming outdated, but what's the harm in knowing what's going on behind the scenes?

    no matter what language you're programming in, it's better practice to write efficient code, rather than clunky, slow code because you've got the "best processor available" and assembly is still valid in terms of efficiency.


  • Closed Accounts Posts: 1,295 ✭✭✭Meh


    Originally posted by MoonHawk
    no matter what language you're programming in, it's better practice to write efficient code, rather than clunky, slow code because you've got the "best processor available" and assembly is still valid in terms of efficiency.
    My point is that compilers generate more efficient assembly code than humans do. It's a much better use of a programmer's time to optimise the algorithm and let the compiler translate it into optimizes assembly, which is what it does best.. I'm not arguing that efficiency isn't needed any more now that we have the PENTIUM 4 that makes the INTARWEB GO FASTAR.


  • Advertisement
  • Posts: 0 [Deleted User]


    Ah right sorry, didn't get your point first time round.

    yeah i agree that the compiler does all that and saves the programmer time with doing the same assebly code over and over...i suppose that's what computers were built for, to automate repetitive tasks.

    There are some things in programming that you dont' want to have to do over and over again, and if you think about how things are being done, then you'll overload your mind...good thing for compilers then...my point is that it's still handy to have an understanding of assembly so you know what the compiler is doing, that you won't be programming without a notion of what it's doing.


  • Closed Accounts Posts: 1,651 ✭✭✭Enygma


    Originally posted by Trojan

    But there is room for an elitist attitude when you're in the pub with your Java/C#/html-loving mates, and there is room for an elitist attitude when you're slagging on a BBS

    LOL! yeah I suppose there is :)


  • Registered Users, Registered Users 2 Posts: 16,414 ✭✭✭✭Trojan


    Originally posted by Enygma

    LOL! yeah I suppose there is :)

    Finally, somebody gets it - ye were all getting a bit too serious back there!

    Reply to MoonHawk: it's C I'm doing at the moment, and it isn't mad low-level or anything, it's above the kernel (most of the time), but still what I'd term system programming. We don't do much assembler, leave it to the compiler 99% of the time.

    That's not to say that I agree with Meh...
    Originally posted by Meh

    My point is that compilers generate more efficient assembly code than humans do

    Nice one. But wrong. :)

    Perhaps what you intended to say was "compilers will, in certain circumstances,[0] generate more efficient assembly code than humans do".

    You application programmers have things too easy with your flashy IDEs and tab-completed keywords - it shows in your laziness in language!! ;)

    Al.

    0: I would also accept any of: "sometimes", "usually", "a lot of the time", "normally" and one or 2 other terms. It's in no way black and white.


  • Registered Users, Registered Users 2 Posts: 897 ✭✭✭Greenbean


    Now, I have to admit I'm no expert in this field - but it would seem to me that the optimisations that compilers can do today can only be "local" optimisations and generally things that are clear to the average programmer. But I would doubt that a compiler could start optimising code at assembly level for the more fancier tricks that surely exist. We're talking about, I dunno, throwing in instructions when you know there will be a .02ms gap in the bus, that only you can know about - due to the design of your program, that the compiler could never really see.. something thats part of the bigger picture. I had assumed that this was where the main gains in assembly language would come from - check out some of the old 64kb intros from the demo scene, they are definitely doing things with the cpu that programmed from even C would not be possible.

    About the "trendy"-ness of high level programming languages - yep, no point in messing around doing work you don't need to be doing, but from an educational view point they are a big barrier. I reckon the more basic the language you learn the greater the understanding you can aim to get. Its only now that I see what the hell is going on with Java and why we declared everything on the heap - not that I knew I was doing that at the time. Even the basics of the range of values you can represent with a signed and unsigned int are rarely focused on in college - its good to get down to the nitty gritty and see why your programs in higher level keep breaking - no matter how level they seem, they always end up being restricted by lower level details and you're screwed if you don't know why.

    edited for clarity


  • Posts: 0 [Deleted User]


    no matter how level they seem, they always end up being restricted by lower level details and you're screwed if you don't know why.

    My point exactly greenbean, although nowadays we will do our programming through graphical editors and all that, we will need to know what's happening "behind the scenes" to fully understand what's happening.


  • Registered Users, Registered Users 2 Posts: 15,443 ✭✭✭✭bonkey


    Originally posted by Trojan
    Nice one. But wrong. :)

    Perhaps what you intended to say was "compilers will, in certain circumstances,[0] generate more efficient assembly code than humans do".

    <snip>

    0: I would also accept any of: "sometimes", "usually", "a lot of the time", "normally" and one or 2 other terms. It's in no way black and white.

    I would actually argue for a much simpler replacement.

    Compilers will, on average, generate more efficient assembly code than humans do.

    There will always be specific places where hand-optimising will be the way to go, typically where optimisation can make use of knowledge of the type of data which will be used.

    Of course, compiling code with a compiler has been empirically proven to be a far more time-efficient approach as well, making it the desirable solution in the vast majority of situations.

    On the other hand, its hard to brag about your l33t VB skillz when faced with a x86 assembly guru :)

    jc


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 21,264 ✭✭✭✭Hobbes


    TBH I think asm is way easier then most languages to learn, but it's god awful slow to physically write anything (unless you have libraries) and not very portable.

    I did a bit of x86 back in my DOS days and then it was only for speed reasons and I would normally call the asm from a VBDOS or batch file process already set up. I certainly wouldn't try to do a whole application in it when there are much easier alternatives.

    In a good language (or OS?) the programmer should never have to worry about how the OS/processor works.


  • Registered Users, Registered Users 2 Posts: 16,414 ✭✭✭✭Trojan


    *sigh*

    Now even Hobbes is doing it...
    Originally posted by Hobbes
    In a good language (or OS?) the programmer should never have to worry about how the OS/processor works.

    In a good language (or OS?) the application programmer should never have to worry about how the OS/processor works.

    Otherwise we'd all be going around with nobody knowing what was going on :)

    bonkey: nice one, agree with your points.

    Al.


  • Posts: 0 [Deleted User]


    Well I agree with Trojan, we need to have SOME understanding of how the PC operates, in order for us to become more efficient...just another thing, is C or C++ closer to the architecture than other higher level languages?

    I've done a bit of C, moving into C++ shortly and I've noticed that you can call ASM code from the program itself for various different parts of the code...is this beneficial in C/C++?


  • Registered Users, Registered Users 2 Posts: 897 ✭✭✭Greenbean


    C++ is a subset of C, they're both pretty much based on the same code. In general a huge program made out of C should be faster than C++, though in theory you should make the program quicker in C++, and in reality it should be easier to maintain. The object orientated nature of C++ is another layer of code between it an the CPU - but there are plenty of techniques that can keep it a fairly thin layer, combined with optomised compilers. Taking a quick look at ASM it seems to me that C is far closer to the architecture than I ever thought. If you program with care it could almost be as good as ASM.


  • Registered Users, Registered Users 2 Posts: 2,518 ✭✭✭Hecate


    Taking a quick look at ASM it seems to me that C is far closer to the architecture than I ever thought. If you program with care it could almost be as good as ASM.

    Indeed, we were using the code below in a lab the other day to turn a fan on and off :)


    #include "hc11.h"
    void OnSerialInterrupt(void);
    void FanOn(void);
    void FanOff(void);

    void SerialISR(void)
    {
    /* NOTE: X is pushed automatically by c-compiler */
    /* If any local variables are used don't forget to
    re-adjust the stack */
    OnSerialInterrupt();
    /* stack cleanup and rti */
    asm(" rti");
    }
    void OpenSerialPort(void)
    {
    fptr *ISRPtr;
    asm(" sei ") /* temporarily disable interrupts */
    BAUD = 0x30; /* set data rate to 9600 */
    SCCR1 = 0x0; /* 8 databits, 1 stop bit */
    SCCR2 = 0x2c; /* enable receiver, transmitter and
    receiver interrupts */

    ISRPtr = (fptr *)(unsigned)0x00C5; /* vector is at $00C5 */
    *ISRPtr = SerialISR;
    asm(" cli "); /* re-enable interrupts */
    }
    void TransmitString(char *Str)
    {
    int i;
    i = 0;
    while(Str) {
    SCDR = Str;
    while(!(SCSR & 0x80)); /* wait for tx buffer to empty */


    i++;
    }
    }
    void DisplayMenu(void)
    {
    TransmitString("Welcome to the 68HC11 control menu\r\n");
    TransmitString("Choices:\r\n");
    TransmitString("1. Turn Fan On\r\n");
    TransmitString("2. Turn Fan Off\r\n");

    }
    void FanOn(void)
    {
    PORTA = PORTA | 0x40;
    }
    void FanOff(void)
    {
    PORTA = PORTA & 0xbf;
    }
    void OnSerialInterrupt(void)
    {
    BYTE UserCommand;
    if (SCSR & 0x20) /* Has data Arrived */
    {
    UserCommand = SCDR;
    switch(UserCommand) {
    case '1': FanOn(); break;
    case '2': FanOff(); break;
    }
    DisplayMenu();
    }
    }
    main()
    {
    DDRA = 0xff; /* set up port A as an output port */
    PORTA = 0; /* clear port A at startup */
    OpenSerialPort();
    while(1); /* now sit in idle loop */
    }


  • Advertisement
Advertisement