A Web Test on J2EE 6 and Glassfish 3.1

index.jsp

A simple web page in JSP served as the simple client UI. The action of the button will be calling the another JSP.

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Web Test</title>
    </head>
    <body>
        <h1>Entry Form</h1>
        <form name="Name Input Form" action="response.jsp">
               Enter Your Name: <input type="text" name="name" value="" />
               <input type="submit" value="OK" />
        </form>
    </body>
</html>

NameHandler.java

A simple class to be called in an EJB container.

package org.mypackage.hello;
/**
 *
 * @author henry416
 */
public class NameHandler {
    private String name;
    public NameHandler() {
        name = null;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }

}

response.jsp

A call to an EJB to get the property of the name.

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Web Testing: an EJB/title>
    </head>
    <body>
        <jsp:useBean id="mybean" scope="session" class="org.mypackage.hello.NameHandler" />
        <jsp:setProperty name="mybean" property="name" />
        <h1>Hello, <jsp:getProperty name="mybean" property="name" /> !</h1>
    </body>
</html>

Test on GlassFish 3.1

Deploy to GlassFish, and go to http://localhost:8080/WebTest/

index.jsp displayed in browser

After entering a name and clicking ‘OK’, the url will be rewritten to

http://localhost:8080/WebTest/response.jsp?name=Larry

response.jsp displayed in browser

About henry416
I am a computer technology explorer and an university student based on Toronto. If you have any question, please feel free to discuss and comment here

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s