Basic Doubt in JSP - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Basic Doubt in JSP

ilarumilarum Posts: 28Member
Hi,
I am not familiar with JSP, but with Java yes. There is a very fundamental question. An applet was embedded in a JSP. Now somebody said me that the Applet runs in a separate JVM and the JSP in a separate JVm. How is it. I am not quite clear about this. Could anybody clarify this for me.

With Regards
Murali

Comments

  • treshrtreshr Posts: 326Member
    It is not that hard to understand,'I'll try to explain.

    An applet runs on a client pc and is sort of an application in a webpage.
    JSP is a scripting language that is run on a server.

    Now what happens if you request a JSP page, the server will process the page, get all the JSP commands out of there and run them and de server send only HTML back to the client.
    So what happens is that there is a different process on the server with a JVM. But the application server on the webserver takes less process time than an applet.

    So to make a long story short, an applet runs with a JVM on the clients pc and a JSP is run on the server using an application server with Java.

    Hope this answered your question.

    --=][tReShR][=--

  • ilarumilarum Posts: 28Member
    Hi,
    Thanks for the reply. Well I would like further elaboration on this sentence of yours "But the application server on the webserver takes less process time than an applet". Also one more question. Lets say that I have an Two JSP's Say A and B. The JSP A calls B on the click of a button. Lets say that the JSP A has information like date, time, studentid, studentname etc.. These name-values need to transfered to the JSP B (When I say name-value I mean stdname(Name) Value(Chris) stdid(Name) Value 123). So Both needs to be transferred to JSP B. I suggested that a HashTable could be used to store the name value pairs in JSP A. Because some fields like Date, Time are common and can be retrieved quickly. Is it possible to pass a Hashtable from JSP A to JSP B. If yes considering the above scenario, is passing a hashtable a good one. One more question. Now assume that an Applet is embedded in the JSP B. How can the Applet access the information(Name-Value pairs) available in the JSP. As you have mentioned that the JSP runs on a different JVM and the Applet in a different JVM. Looking forward to a reply.

    With Regards
    Murali

    : It is not that hard to understand,'I'll try to explain.
    :
    : An applet runs on a client pc and is sort of an application in a webpage.
    : JSP is a scripting language that is run on a server.
    :
    : Now what happens if you request a JSP page, the server will process the page, get all the JSP commands out of there and run them and de server send only HTML back to the client.
    : So what happens is that there is a different process on the server with a JVM. But the application server on the webserver takes less process time than an applet.
    :
    : So to make a long story short, an applet runs with a JVM on the clients pc and a JSP is run on the server using an application server with Java.
    :
    : Hope this answered your question.
    :
    : --=][tReShR][=--
    :
    :

  • treshrtreshr Posts: 326Member
    I would use a JavaBean for your solution, that JSP A writes data into a JavaBean and JSP B gets the values out of the JavaBean.

    If you want to pass variables to an applet, I don't know if you can use a JSP page for it, but try using parameters. Maybe the applet is able to get tjose values, but I'm not v ery experienced with applets so I don't reallly know.

    --=][tReShR][=--

  • fzammettifzammetti Posts: 68Member
    Remember that to pass anything from one JSP to another, you'll need some process on the server to first recieve the parameters and then pass them along to the second JSP. Well, I guess that's not completely true... you could submit a form to a JSP and just get the parameters as usual, I believe that works. It's as a rule never done though.

    What the previous poster says about a bean is true, and takes you into MVC architecture. You have to remember that the only thing that can be passed from a web browser to a server are strings. So, it's not even an option to simply pass a HashTable from one JSP to another. Directly, that's not even possible. You would have to do something along the lines of submit a form from JSP A to a servlet, which would take all the form parameters, put them in a HashTable, then pass that along to JSP B. The point of the other poster is that it's better to not pass a naked HashTable like that but instead pass a bean. Depending on what your really trying to do that frankly might be overkill, but it IS the accepted architectural method, generally speaking.

    The other question regarding an applet getting access to those parameters... The only way you can do it is for the applet to access JavaScript variables on your page. So, JSP B would have to render some JavaScript variables, which your applet could then access. This is the case exactly for the reasons previously described by the other posted: your JSP renders on the server, generates some HTML, which is returned to the client's browser. The browser then parses the HTML and sees an applet embed tag. It then requests from the server the applet. So, any request parameters that may have existed at the time JSP B was rendered on the server are long gone. Unless you have persisted them by means of "embedding" them into your generated HTML, there's no way for that applet to get access to them.

    I suppose you could also put the parameters in session on the server and then have your applet request the data from session via a special servlet, but that would just be painful to pull off.

    : I would use a JavaBean for your solution, that JSP A writes data into a JavaBean and JSP B gets the values out of the JavaBean.
    :
    : If you want to pass variables to an applet, I don't know if you can use a JSP page for it, but try using parameters. Maybe the applet is able to get tjose values, but I'm not v ery experienced with applets so I don't reallly know.
    :
    : --=][tReShR][=--
    :
    :

Sign In or Register to comment.