ulrich
2016-12-17 59db0c72ece1e6ad24cd64616609faa0a3eb001b
Merge origin/master

Conflicts:
web/ui/user.jsp
4 files modified
2 files added
177 ■■■■ changed files
src/java/de/uhilger/um/api/UserMgr.java 4 ●●●● patch | view | raw | blame | history
src/java/de/uhilger/um/web/NiceFilter.java 43 ●●●●● patch | view | raw | blame | history
web/WEB-INF/web.xml 28 ●●●●● patch | view | raw | blame | history
web/show.jsp 26 ●●●●● patch | view | raw | blame | history
web/ui/ui.js 62 ●●●●● patch | view | raw | blame | history
web/ui/user.jsp 14 ●●●● patch | view | raw | blame | history
src/java/de/uhilger/um/api/UserMgr.java
@@ -24,4 +24,8 @@
    return user;
  }
  
  public String hallo() {
    return "Hallo Welt";
  }
}
src/java/de/uhilger/um/web/NiceFilter.java
New file
@@ -0,0 +1,43 @@
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package de.uhilger.um.web;
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
/**
 *
 * @author hilgeru
 */
public class NiceFilter implements Filter {
  @Override
  public void init(FilterConfig filterConfig) throws ServletException {
    // ...
  }
  @Override
  public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
    if(request instanceof HttpServletRequest) {
      HttpServletRequest hr = (HttpServletRequest) request;
      String servletPath = hr.getServletPath();
      String[] path = servletPath.split("/");
      request.getRequestDispatcher("../api?c=de.uhilger.um.api.UserMgr&m=" + path[2]).forward(request, response);
    }
  }
  @Override
  public void destroy() {
    // ...
  }
}
web/WEB-INF/web.xml
@@ -5,9 +5,37 @@
        <param-name>dsname</param-name>
        <param-value>jdbc/NewUserDB</param-value>
    </context-param>
    <filter>
        <filter-name>NiceFilter</filter-name>
        <filter-class>de.uhilger.um.web.NiceFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>NiceFilter</filter-name>
        <url-pattern>/svc/*</url-pattern>
    </filter-mapping>
    <listener>
        <listener-class>de.uhilger.um.App</listener-class>
    </listener>
    <servlet>
        <servlet-name>TransitServlet</servlet-name>
        <servlet-class>de.uhilger.transit.web.TransitServlet</servlet-class>
        <init-param>
            <param-name>klassen</param-name>
            <param-value>de.uhilger.um.api</param-value>
        </init-param>
    </servlet>
    <servlet>
        <servlet-name>TestServlet</servlet-name>
        <jsp-file>/show.jsp</jsp-file>
    </servlet>
    <servlet-mapping>
        <servlet-name>TransitServlet</servlet-name>
        <url-pattern>/api</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>TestServlet</servlet-name>
        <url-pattern>/test/*</url-pattern>
    </servlet-mapping>
    <session-config>
        <session-timeout>
            30
web/show.jsp
New file
@@ -0,0 +1,26 @@
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>um Werte</title>
  </head>
  <body>
    <p>Werte</p>
    <p>pathInfo: <%=request.getPathInfo()%></p>
    <p>requestURL <%=request.getRequestURL()%></p>
    <p>contextPath <%=request.getContextPath()%></p>
    <p>servletPath <%=request.getServletPath()%></p>
    <p>
      <%
        String pathInfo = request.getPathInfo();
        String[] path = pathInfo.split("/");
        for(int i = 0; i < path.length; i++) {
       %>
        <p>path[<%=i%>]: <%=path[i]%></p>
       <%
        }
       %>
    </p>
  </body>
</html>
web/ui/ui.js
@@ -1,22 +1,27 @@
/*
  Beispiel aus Spot fuer den Post eines Coordinates-Objektes
function um_init() {
  $('.user-save-btn').click(um_user_save);
}
    var coord = new Coordinates(
                    c.latitude,
                    c.longitude,
                    self.nummer(c.altitude),
                    self.nummer(c.accuracy),
                    self.nummer(c.altitudeAccuracy),
                    self.nummer(c.heading),
                    self.nummer(c.speed));
            var cObj = self.serialisieren(coord);
function um_user_save() {
  var user = um_user_form_lesen();
  var kww = $('#kennwortw').val();
  if(user.pw != kww) {
    alert('Kennworte stimmen nicht ueberein.');
  } else {
    alert('user-save ' + user.id);
    um_apicall(self.serialisieren(user));
  }
}
function um_apicall(obj) {
  var c = 'de.uhilger.um.api.UserMgr';
  var m = 'createUser';
  var u = '../api?c=' + c + '&m=' + m;
            $.ajax({
              url: '../rpc?c=de.uhilger.spot.api.NutzerApi&m=ortSpeichern',
    url: u,
              data: {
                p: cObj
      p: obj
              },
              type: "POST",
              dataType : "html",
@@ -30,20 +35,23 @@
                //alert( "The request is complete!" );
              }
            });      
            usw.
  function Coordinates(la, lo, al, ac, aa, hd, sp) {
   this.latitude = la;
   this.longitude = lo;
   this.altitude = al;
   this.accuracy = ac;
   this.altitudeAccuracy = aa;
   this.heading = hd;
   this.speed = sp;
}
 
function um_user_form_lesen() {
  var userId = $('#anmeldename').val();
  var kw = $('#kennwort').val();
  var user = new User(userId, kw, '-', '-', '-');
  return user;
}
 
function serialisieren(obj) {
  return '{"' + obj.constructor.name + '":' + JSON.stringify(obj) + '}';
};
 
 */
function User(i, p, fn, ln, em) {
  this.id = i;
  this.pw = p;
  this.firstName = fn;
  this.lastName = ln;
  this.email = em;
}
web/ui/user.jsp
@@ -10,15 +10,25 @@
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Benutzer</title>
    <link rel="stylesheet" href="/jslib/skeleton-2.0.4/css/normalize.css">
    <link rel="stylesheet" href="/jslib/skeleton-2.0.4/css/skeleton.css">
    <link rel="stylesheet" type="text/css" href="stile.css">
  </head>
  <body>
    <h1>Benutzer</h1>
    <div>
    <div id="user-form">
      <input type="text" size="20" maxlength="20" placeholder="Anmeldename" name="anmeldename" id="anmeldename">
      <input type="password" size="20" maxlength="20" placeholder="Kennwort" name="kennwort" id="kennwort">
      <input type="password" size="20" maxlength="20" placeholder="Wiederholung" name="kennwortw" id="kennwortw">
      <button>OK</button>
      <button class="user-save-btn">OK</button>
    </div>
    <script src="/jslib/jquery-1.11.1/jquery-1.11.1.min.js"></script>
    <script src="ui.js"></script>
    <script type="text/javascript" charset="utf-8">
      //var ui;
      $(document).ready(function() {
        um_init();
      });
    </script>
  </body>
</html>