Implementing the Client User Interface

The client user interface provides the required functionality to the user.

The application layer is provided by the SampleApp project. The contents of the project are:

File Description
WorkProcessingServlet.java Creates and manages the SampleApp.

The class WorkProcessingServlet contains all the methods required to handle the flow of the sample application. It orchestrates the JSP pages that are displayed and calls the appropriate Service Connector method based on the user’s actions and data supplied by the user.

login.jsp Creates and manages the Login form, which provides the Login dialog. The Login form provides the entry point to the sample application.
worklist.jsp Creates and manages the user’s interaction with work lists.
openworkitem.jsp Creates and manages the user’s interaction with a specific work item.

The process method in WorkProcessingServlet.java is called whenever the user performs an action. Based on the action performed, it calls the method to be executed next.

For example, when a user submits the login information, information sent to the servlet by login.jsp is:

<form action="">
		<label for="username">Username:</label>
		<input type="text" name="userName" class="text" id="username">
		<br />
		<label for="password">Password:</label>
		<input type="password" name="pass" class="text" id="password">
		<br />
		<serverLabel for="protocol">Server:</label>
		<input type="checkbox" name="secure" value="secure" checked="checked">Secure (https)</input>
        <!-- <serverLabel for="protocol">Protocol:</serverLabel>
        <input type="radio" name="protocol" value="HTTP" checked="checked">HTTP</input>
        <input type="radio" name="protocol" value="HTTPS">HTTPS</input> -->
        <br /><br />
        <serverLabel for="host">Host:</serverLabel>
		<input class="serverInput" type="text" name="host" class="text" id="host" value="localhost">
		<br /><br />
		<serverLabel for="port">Port:</serverLabel>
		<input class="serverInput"  type="text" name="port" class="text" id="port" value="8080">
        <br /><br />
		<input type="submit" onclick="submitData('login');" class="submit" name="submit" value="Submit">
	</form>
</div>
</body>
</html>

The process method in WorkProcessingServlet.java identifies the action as ’login’ and hence executes:

public void process(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
	{if (getAction(req).equals(Actions.LOGIN))
		{
			setServiceConnector(req);
			authenticate(req, resp);
		}
...
orchestratePages(req, resp);
}

Once the user is authenticated, it calls the orchestratePages method which displays pages according to the action invoked by the user. For example, after the action LOGIN is completed, worklist.jsp is displayed to the user. worklist.jsp displays the list of worklist items available for the logged in user in a tabular form.

private void orchestratePages(HttpServletRequest req, HttpServletResponse resp) throws ServletException,IOException
	{
if (getAction(req).equals(Actions.LOGIN))
		{
			getServletContext().getRequestDispatcher("/worklist.jsp").forward(req, resp);
		}
...
}