Phil 10.1.14

8:00 – 4:00 SR

  • Still no server access. Looks like Dave W. is the hangup. Also, the reason that Ronda can’t get her Centrify account is because she doesn’t have access either.
  • Added an “EchoServlet” to the YUITestServlets for playing with Angular. In retrospect, maybe we should have called this the JS-JavaServlets. Ah, well. Lockin sucks.
  • After considerable flailing, figured out how to handle deployments (to the local Tomcat Server) in Webstorm. The process is as follows:
  • Under the Tools tab, select ‘Deployment’, then ‘Configuration’. This will bring up the dialog that appears below. Click the green ‘plus’ to add a configuration.
  • DeploymentConnection
  • Give the configuration and a name, then set up the project file and urls as shown. Once that’s done, you can configure the mappings. Note that if the deployment options in the Tools->Deployment tab are disabled, you’ve probably messed up a mapping, so be careful here:
  • DeploymentMapping
  • The tricky part that I found is that there has to be at leas a ‘\’ in the deployment path or this doesn’t work. So just follow the above template and things ‘should’ work.
  • Ok, got everything working. The following is a complete example that echoes the request from the client back from the server
  • First, the html
<!DOCTYPE html>
<html ng-app="queryAppServlet">
<head lang="en">
 <meta charset="UTF-8">
 .queryDiv {
 background-color: lightgrey;
 width: 700px;
 height: 200px;
 padding: 5px;
 margin: 5px;
 overflow: auto;

 .responseDiv {
 background-color: lightgrey;
 width: 700px;
 height: 400px;
 padding: 5px;
 margin: 5px;
 overflow: auto;

 font-size: 12px;
 font-style: italic;
 font-family: "Courier New";
 font-size: 12px;
<body body ng-controller="MainCtrl as mainCtrl">
<div>Raw queries of irev database. Copy results and paste into Excel or .csv file</div>
<textarea class="queryDiv"contenteditable="true" ng-model="mainCtrl.query"></textarea>
<input type="button" value="Submit Query" ng-click = "mainCtrl.submit()"/>
<div class="responseDiv">
 <p class = "messages">{{mainCtrl.message}}</p>
 <div class = "results" ng-repeat="item in mainCtrl.items"> {{item}}</div>

<script src="libs/angular.js"> </script>
<script src="queryAppServlet.js"></script>
  • Next, the Angular component:
var qa = angular.module('queryAppServlet', []);
qa.controller('MainCtrl', ['$http', function ($http) {
 "use strict";
 var self = this;
 self.items = ["Ready"];
 self.message = "No Messages";
 self.submit = function () {
 self.message = "No Messages";
 var upstring = encodeURI("query=" + self.query);
 var upObj = {
 url: 'EchoServlet/foo.json',
 method: "POST",
 data: upstring,
 headers: {'Content-Type': 'application/x-www-form-urlencoded'}

 function goodResponse(response){
 var data =;
 if (data['database access']) {
 self.message = data['database access'];
 self.items = [];
 if (data.connect_error) {
 self.message = data.connect_error;
 self.items = [];
 self.items = [];
 var item;
 var keys = Object.keys(data[0]);
 var key;
 var i = 0, j = 0;
 var str = "";
 for (i = 0; i < keys.length; i++) {
 str += keys[i] + ', ';
 for (i = 0; i < data.length; i++) {
 item = data[i];
 str = "";
 for (j = 0; j < keys.length; j++) {
 key = keys[j];
 str += item[key] + ', ';

 function errorResponse(response){
 alert('queryApp.js: Error while fetching data from io2.php: '+response);

 $http(upObj).then(goodResponse, errorResponse);
  • Last, the Java Servlet
 package com.novetta.yuitest;

import java.util.ArrayList;
import java.util.Enumeration;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;

public class EchoServlet extends HttpServlet {
 protected Logger logger = Logger.getLogger(EchoServlet.class.getName());

 public EchoServlet() {
 // TODO Auto-generated constructor stub
 public void doPost(HttpServletRequest req, HttpServletResponse rsp)
 throws ServletException
 Enumeration<String> pNames = req.getParameterNames();
 ArrayList<String> nameArray = new ArrayList<String>();
 ArrayList<String> valArray = new ArrayList<String>();
 String pName = pNames.nextElement().toString();
 String pVal = req.getParameter(pName);
 System.out.println(pName+" = '"+pVal+"'");
 PrintWriter out;
 try {
 String buf = "[";
 for(int i = 0; i < nameArray.size(); i++){
 buf += "{\""+nameArray.get(i)+"\":\""+valArray.get(i)+"\"},";
 buf = buf.substring(0, buf.length()-1);
 buf += "]";
 out = rsp.getWriter();

 } catch (IOException e) {


 * @param args
 public static void main(String[] args) {
 // TODO Auto-generated method stub



Leave a Reply

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

You are commenting using your 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