Bright Java Tutorial

is brought to you by DoITBright LLC


JSP Scriptlets

A JSP scriptlet is surrounded by <% and %>. It is used to contain any valid Java code. It is a Java code embeded in an HTML document.

It is assumed that you have prior knowledge in both Java and HTML. If not, I highly suggest for you to go over my Java Tutorial and / or my HTML Tutorial.

Create a file inside your 'jspLessons' folder and name it as 'firstJspScriptlet.jsp'. Do not forget to make sure to save it as a JSP extension file name.

        //this is a single line comment
        int anInt = 0;
        //we just declared an int variable named anInt.
        anInt = anInt + 1;
        //we just incremented the value of anInt by 1.
        out.println("anInt = " + anInt);
Copy the 'jspLessons' folder to your tomcat webapps directory. Start your tomcat application server. You may now view the page you have just created.

As you may have seen, we are now able to embed valid Java code on our HTML. One thing you must under stand, and should always remember, JSP is run at the application server, HTML is run at your local machine. So what does it mean? While we have our JSP code shown above, what actually gets downloaded on our browser is purely HTML. There is no trace of JSP. I maybe wrong but to somehow prove this, view the page source of the generated HTML on your browser. It should look something like this.
        anInt = 1

Back    Next