Advertisement
Guest User

Untitled

a guest
Nov 20th, 2017
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 38.21 KB | None | 0 0
  1. diff --git a/nbproject/private/private.xml b/nbproject/private/private.xml
  2. index df5bdd2..0bd119d 100644
  3. --- a/nbproject/private/private.xml
  4. +++ b/nbproject/private/private.xml
  5. @@ -3,11 +3,19 @@
  6. <editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/2" lastBookmarkId="0"/>
  7. <open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2">
  8. <group>
  9. - <file>file:/D:/Privat/Klassenmanager/webapp/src/java/beans/School.java</file>
  10. + <file>file:/D:/Privat/Klassenmanager/webapp/src/java/beans/Homework.java</file>
  11. + <file>file:/D:/Privat/Klassenmanager/webapp/src/java/servlets/SchoolClassSwitcher.java</file>
  12. + <file>file:/D:/Privat/Klassenmanager/webapp/web/jsp/klassen.jsp</file>
  13. + <file>file:/D:/Privat/Klassenmanager/webapp/src/java/beans/SchoolClass.java</file>
  14. + <file>file:/D:/Privat/Klassenmanager/webapp/src/java/misc/URLConnection.java</file>
  15. + <file>file:/D:/Privat/Klassenmanager/webapp/src/java/servlets/SiteSwitcher.java</file>
  16. <file>file:/D:/Privat/Klassenmanager/webapp/web/index.jsp</file>
  17. <file>file:/D:/Privat/Klassenmanager/webapp/src/java/servlets/LoginServlet.java</file>
  18. + <file>file:/D:/Privat/Klassenmanager/webapp/src/java/misc/BeanFiller.java</file>
  19. <file>file:/D:/Privat/Klassenmanager/webapp/src/java/beans/Teacher.java</file>
  20. - <file>file:/D:/Privat/Klassenmanager/webapp/src/java/misc/URLConnection.java</file>
  21. + <file>file:/D:/Privat/Klassenmanager/webapp/web/css/style.css</file>
  22. + <file>file:/D:/Privat/Klassenmanager/webapp/web/jsp/home.jsp</file>
  23. + <file>file:/D:/Privat/Klassenmanager/webapp/src/java/beans/Event.java</file>
  24. </group>
  25. </open-files>
  26. </project-private>
  27. diff --git a/src/java/beans/AssigendDate.java b/src/java/beans/AssigendDate.java
  28. new file mode 100644
  29. index 0000000..17d757a
  30. --- /dev/null
  31. +++ b/src/java/beans/AssigendDate.java
  32. @@ -0,0 +1,25 @@
  33. +package beans;
  34. +
  35. +import java.sql.Date;
  36. +
  37. +public class AssigendDate {
  38. +
  39. + private int id;
  40. + private Date date;
  41. +
  42. + public int getId() {
  43. + return id;
  44. + }
  45. +
  46. + public void setId(int id) {
  47. + this.id = id;
  48. + }
  49. +
  50. + public Date getDate() {
  51. + return date;
  52. + }
  53. +
  54. + public void setDate(Date date) {
  55. + this.date = date;
  56. + }
  57. +}
  58. diff --git a/src/java/beans/Event.java b/src/java/beans/Event.java
  59. new file mode 100644
  60. index 0000000..9aea986
  61. --- /dev/null
  62. +++ b/src/java/beans/Event.java
  63. @@ -0,0 +1,49 @@
  64. +package beans;
  65. +
  66. +public class Event {
  67. + private int id;
  68. + private String description;
  69. + private String title;
  70. + private SchoolClass schoolclass;
  71. + private SchoolDate schooldate;
  72. +
  73. + public int getId() {
  74. + return id;
  75. + }
  76. +
  77. + public void setId(int id) {
  78. + this.id = id;
  79. + }
  80. +
  81. + public String getDescription() {
  82. + return description;
  83. + }
  84. +
  85. + public void setDescription(String description) {
  86. + this.description = description;
  87. + }
  88. +
  89. + public String getTitle() {
  90. + return title;
  91. + }
  92. +
  93. + public void setTitle(String title) {
  94. + this.title = title;
  95. + }
  96. +
  97. + public SchoolClass getSchoolclass() {
  98. + return schoolclass;
  99. + }
  100. +
  101. + public void setSchoolclass(SchoolClass schoolclass) {
  102. + this.schoolclass = schoolclass;
  103. + }
  104. +
  105. + public SchoolDate getSchooldate() {
  106. + return schooldate;
  107. + }
  108. +
  109. + public void setSchooldate(SchoolDate schooldate) {
  110. + this.schooldate = schooldate;
  111. + }
  112. +}
  113. diff --git a/src/java/beans/Homework.java b/src/java/beans/Homework.java
  114. new file mode 100644
  115. index 0000000..dbbb91b
  116. --- /dev/null
  117. +++ b/src/java/beans/Homework.java
  118. @@ -0,0 +1,67 @@
  119. +package beans;
  120. +
  121. +public class Homework {
  122. + private int id;
  123. + private String homework;
  124. + private SchoolClass schoolclass;
  125. + private Subject subject;
  126. + private SchoolDate schooldate;
  127. + private Teacher teacher;
  128. + private AssigendDate assigenddate;
  129. +
  130. + public int getId() {
  131. + return id;
  132. + }
  133. +
  134. + public void setId(int id) {
  135. + this.id = id;
  136. + }
  137. +
  138. + public String getHomework() {
  139. + return homework;
  140. + }
  141. +
  142. + public void setHomework(String homework) {
  143. + this.homework = homework;
  144. + }
  145. +
  146. + public SchoolClass getSchoolclass() {
  147. + return schoolclass;
  148. + }
  149. +
  150. + public void setSchoolclass(SchoolClass schoolclass) {
  151. + this.schoolclass = schoolclass;
  152. + }
  153. +
  154. + public Subject getSubject() {
  155. + return subject;
  156. + }
  157. +
  158. + public void setSubject(Subject subject) {
  159. + this.subject = subject;
  160. + }
  161. +
  162. + public SchoolDate getSchooldate() {
  163. + return schooldate;
  164. + }
  165. +
  166. + public void setSchooldate(SchoolDate schooldate) {
  167. + this.schooldate = schooldate;
  168. + }
  169. +
  170. + public Teacher getTeacher() {
  171. + return teacher;
  172. + }
  173. +
  174. + public void setTeacher(Teacher teacher) {
  175. + this.teacher = teacher;
  176. + }
  177. +
  178. + public AssigendDate getAssigenddate() {
  179. + return assigenddate;
  180. + }
  181. +
  182. + public void setAssigenddate(AssigendDate assigenddate) {
  183. + this.assigenddate = assigenddate;
  184. + }
  185. +}
  186. diff --git a/src/java/beans/Pupil.java b/src/java/beans/Pupil.java
  187. new file mode 100644
  188. index 0000000..814d1a5
  189. --- /dev/null
  190. +++ b/src/java/beans/Pupil.java
  191. @@ -0,0 +1,78 @@
  192. +package beans;
  193. +
  194. +public class Pupil {
  195. + private int id;
  196. + private String password;
  197. + private String email;
  198. + private String firstname;
  199. + private String lastname;
  200. + private String pupilHash;
  201. + private boolean activated;
  202. + private SchoolClass schoolclass;
  203. +
  204. + public int getId() {
  205. + return id;
  206. + }
  207. +
  208. + public void setId(int id) {
  209. + this.id = id;
  210. + }
  211. +
  212. + public String getPassword() {
  213. + return password;
  214. + }
  215. +
  216. + public void setPassword(String password) {
  217. + this.password = password;
  218. + }
  219. +
  220. + public String getEmail() {
  221. + return email;
  222. + }
  223. +
  224. + public void setEmail(String email) {
  225. + this.email = email;
  226. + }
  227. +
  228. + public String getFirstname() {
  229. + return firstname;
  230. + }
  231. +
  232. + public void setFirstname(String firstname) {
  233. + this.firstname = firstname;
  234. + }
  235. +
  236. + public String getLastname() {
  237. + return lastname;
  238. + }
  239. +
  240. + public void setLastname(String lastname) {
  241. + this.lastname = lastname;
  242. + }
  243. +
  244. + public String getPupilHash() {
  245. + return pupilHash;
  246. + }
  247. +
  248. + public void setPupilHash(String pupilHash) {
  249. + this.pupilHash = pupilHash;
  250. + }
  251. +
  252. + public boolean isActivated() {
  253. + return activated;
  254. + }
  255. +
  256. + public void setActivated(boolean activated) {
  257. + this.activated = activated;
  258. + }
  259. +
  260. + public SchoolClass getSchoolclass() {
  261. + return schoolclass;
  262. + }
  263. +
  264. + public void setSchoolclass(SchoolClass schoolclass) {
  265. + this.schoolclass = schoolclass;
  266. + }
  267. +
  268. +
  269. +}
  270. diff --git a/src/java/beans/School.java b/src/java/beans/School.java
  271. index 2b3ae52..6a64bd8 100644
  272. --- a/src/java/beans/School.java
  273. +++ b/src/java/beans/School.java
  274. @@ -1,8 +1,5 @@
  275. package beans;
  276.  
  277. -/**
  278. - * Created by Matze on 15.07.2017.
  279. - */
  280. public class School {
  281. private int id;
  282. private String name;
  283. diff --git a/src/java/beans/SchoolClass.java b/src/java/beans/SchoolClass.java
  284. new file mode 100644
  285. index 0000000..dd0540b
  286. --- /dev/null
  287. +++ b/src/java/beans/SchoolClass.java
  288. @@ -0,0 +1,40 @@
  289. +package beans;
  290. +
  291. +public class SchoolClass {
  292. + private int id;
  293. + private String name;
  294. + private School school;
  295. + private Pupil[] pupil;
  296. +
  297. + public int getId() {
  298. + return id;
  299. + }
  300. +
  301. + public void setId(int id) {
  302. + this.id = id;
  303. + }
  304. +
  305. + public String getName() {
  306. + return name;
  307. + }
  308. +
  309. + public void setName(String name) {
  310. + this.name = name;
  311. + }
  312. +
  313. + public School getSchool() {
  314. + return school;
  315. + }
  316. +
  317. + public void setSchool(School school) {
  318. + this.school = school;
  319. + }
  320. +
  321. + public Pupil[] getPupil() {
  322. + return pupil;
  323. + }
  324. +
  325. + public void setPupil(Pupil[] pupil) {
  326. + this.pupil = pupil;
  327. + }
  328. +}
  329. diff --git a/src/java/beans/SchoolDate.java b/src/java/beans/SchoolDate.java
  330. new file mode 100644
  331. index 0000000..c78d80d
  332. --- /dev/null
  333. +++ b/src/java/beans/SchoolDate.java
  334. @@ -0,0 +1,25 @@
  335. +package beans;
  336. +
  337. +import java.util.Date;
  338. +
  339. +
  340. +public class SchoolDate {
  341. + private int id;
  342. + private Date date;
  343. +
  344. + public int getId() {
  345. + return id;
  346. + }
  347. +
  348. + public void setId(int id) {
  349. + this.id = id;
  350. + }
  351. +
  352. + public Date getDate() {
  353. + return date;
  354. + }
  355. +
  356. + public void setDate(Date date) {
  357. + this.date = date;
  358. + }
  359. +}
  360. diff --git a/src/java/beans/Subject.java b/src/java/beans/Subject.java
  361. new file mode 100644
  362. index 0000000..c09a63d
  363. --- /dev/null
  364. +++ b/src/java/beans/Subject.java
  365. @@ -0,0 +1,22 @@
  366. +package beans;
  367. +
  368. +public class Subject {
  369. + private int id;
  370. + private String subject;
  371. +
  372. + public int getId() {
  373. + return id;
  374. + }
  375. +
  376. + public void setId(int id) {
  377. + this.id = id;
  378. + }
  379. +
  380. + public String getSubject() {
  381. + return subject;
  382. + }
  383. +
  384. + public void setSubject(String subject) {
  385. + this.subject = subject;
  386. + }
  387. +}
  388. diff --git a/src/java/beans/Teacher.java b/src/java/beans/Teacher.java
  389. index d7be874..973a51c 100644
  390. --- a/src/java/beans/Teacher.java
  391. +++ b/src/java/beans/Teacher.java
  392. @@ -1,8 +1,5 @@
  393. package beans;
  394.  
  395. -/**
  396. - * Created by Matze on 15.07.2017.
  397. - */
  398. public class Teacher {
  399. private int id;
  400. private String firstname;
  401. diff --git a/src/java/beans/User.java b/src/java/beans/User.java
  402. new file mode 100644
  403. index 0000000..a25a453
  404. --- /dev/null
  405. +++ b/src/java/beans/User.java
  406. @@ -0,0 +1,19 @@
  407. +package beans;
  408. +
  409. +public class User {
  410. + private final String type;
  411. + private final Object object;
  412. +
  413. + public User(String type, Object object){
  414. + this.type = type;
  415. + this.object = object;
  416. + }
  417. +
  418. + public String getType() {
  419. + return type;
  420. + }
  421. +
  422. + public Object getObject() {
  423. + return object;
  424. + }
  425. +}
  426. diff --git a/src/java/misc/BeanChanger.java b/src/java/misc/BeanChanger.java
  427. new file mode 100644
  428. index 0000000..3557285
  429. --- /dev/null
  430. +++ b/src/java/misc/BeanChanger.java
  431. @@ -0,0 +1,28 @@
  432. +package misc;
  433. +
  434. +import java.io.IOException;
  435. +import javax.servlet.http.HttpServletRequest;
  436. +import javax.servlet.http.HttpServletResponse;
  437. +import javax.servlet.http.HttpSession;
  438. +
  439. +public class BeanChanger {
  440. +
  441. + private final HttpServletRequest request;
  442. + private final HttpServletResponse response;
  443. + private final HttpSession session;
  444. + private final URLConnection connection;
  445. +
  446. + public BeanChanger(HttpServletRequest request, HttpServletResponse response) {
  447. + this.response = response;
  448. + this.request = request;
  449. + this.session = this.request.getSession();
  450. + this.connection = new URLConnection();
  451. + }
  452. +
  453. + public void addSchoolClassForTeacher(int schoolClassId, int teacherId) throws IOException{
  454. + String json = "{schoolclassid: " + schoolClassId + ", teacherid: " + teacherId + "}";
  455. + String postResponse = connection.post("classgroup", json);
  456. +
  457. + //Fehlermeldung einbauen!
  458. + }
  459. +}
  460. diff --git a/src/java/misc/BeanFiller.java b/src/java/misc/BeanFiller.java
  461. new file mode 100644
  462. index 0000000..ec11b95
  463. --- /dev/null
  464. +++ b/src/java/misc/BeanFiller.java
  465. @@ -0,0 +1,141 @@
  466. +package misc;
  467. +
  468. +import beans.Event;
  469. +import beans.Homework;
  470. +import beans.Pupil;
  471. +import beans.SchoolClass;
  472. +import beans.Subject;
  473. +import beans.Teacher;
  474. +import beans.User;
  475. +import com.google.gson.Gson;
  476. +import com.google.gson.GsonBuilder;
  477. +import java.io.IOException;
  478. +import java.util.ArrayList;
  479. +import java.util.Arrays;
  480. +import javax.servlet.RequestDispatcher;
  481. +import javax.servlet.ServletException;
  482. +import javax.servlet.http.HttpServletRequest;
  483. +import javax.servlet.http.HttpServletResponse;
  484. +import javax.servlet.http.HttpSession;
  485. +
  486. +public class BeanFiller {
  487. +
  488. + private final HttpServletRequest request;
  489. + private final HttpServletResponse response;
  490. + private final HttpSession session;
  491. +
  492. + public BeanFiller(HttpServletRequest request, HttpServletResponse response) {
  493. + this.response = response;
  494. + this.request = request;
  495. + this.session = this.request.getSession();
  496. + }
  497. +
  498. + public void fillTeacherBeans(String json) throws IOException, ServletException{
  499. + createTeacherBean(json);
  500. + User user = (User) this.session.getAttribute("user");
  501. + Teacher teacher = (Teacher) user.getObject();
  502. + createSchoolClassBean(teacher.getId());
  503. + createEventsBeanBySchoolId(teacher.getSchool().getId());
  504. + createHomeworkBeanByTeacher(teacher.getId());
  505. + }
  506. +
  507. + public void fillChildBeans(String json) throws IOException, ServletException{
  508. + //String postResponse = checkLogin(json);
  509. + }
  510. +
  511. + public void fillParentBeans(String json) throws IOException, ServletException{
  512. + //String postResponse = checkLogin(json);
  513. + }
  514. +
  515. + public void fillSchoolAdminBeans(String json) throws IOException, ServletException{
  516. + // String postResponse = checkLogin(json);
  517. + }
  518. +
  519. + public void fillMinisteriumBeans(String json) throws IOException, ServletException{
  520. + //String postResponse = checkLogin(json);
  521. + }
  522. +
  523. + public void fail() throws ServletException, IOException{
  524. + request.getSession().invalidate();
  525. + RequestDispatcher dispatcher = request.getRequestDispatcher("/jsp/home.jsp");
  526. + dispatcher.forward(request, response);
  527. + }
  528. +
  529. + private void createTeacherBean(String json) throws IOException{
  530. + URLConnection connection = new URLConnection();
  531. + String postResponse = connection.post("login", json);
  532. + Gson g = new GsonBuilder().create();
  533. + Teacher teacher = g.fromJson(postResponse, Teacher[].class)[0];
  534. +
  535. + User user = new User("teacher", teacher);
  536. + this.session.setAttribute("user", user);
  537. + }
  538. +
  539. + public void createSchoolClassBean(int teacherId) throws IOException{
  540. + URLConnection connection = new URLConnection();
  541. + String getResponse = connection.get("schoolclass?teacherid=" + 1); //+ teacherId
  542. + Gson g = new GsonBuilder().create();
  543. + SchoolClass[] schoolClass = g.fromJson(getResponse, SchoolClass[].class); //vllt. in eine ArrayList packen, besser in JSP
  544. +
  545. + for(SchoolClass school : schoolClass){
  546. + school.setPupil(createPupilBeanForSchoolClass(school.getId()));
  547. + }
  548. +
  549. + this.session.setAttribute("schoolclass", schoolClass);
  550. + }
  551. +
  552. + public Pupil[] createPupilBeanForSchoolClass(int schoolClassId) throws IOException{
  553. + URLConnection connection = new URLConnection();
  554. + String getResponse = connection.get("pupil?schoolclassid=" + schoolClassId);
  555. + Gson g = new GsonBuilder().create();
  556. + Pupil[] pupil = g.fromJson(getResponse, Pupil[].class); //vllt. in eine ArrayList packen, besser in JSP
  557. + return pupil;
  558. + }
  559. +
  560. + public void createSpecificPupilBeanForSchoolClass(int schoolClassId){
  561. + ArrayList<Pupil> pupilList = new ArrayList<>();
  562. + SchoolClass[] schoolClass = (SchoolClass[]) this.session.getAttribute("schoolclass");
  563. + for(SchoolClass school : schoolClass){
  564. + if(school.getId() == schoolClassId)
  565. + pupilList.addAll(Arrays.asList(school.getPupil()));
  566. + }
  567. + this.session.setAttribute("pupils", pupilList);
  568. + }
  569. +
  570. + public void createHomeworkBeanByTeacher(int teacherId) throws IOException{
  571. + URLConnection connection = new URLConnection();
  572. + String getResponse = connection.get("homework?teacherid=" + teacherId);
  573. + Gson g = new GsonBuilder().create();
  574. + Homework[] homework = g.fromJson(getResponse, Homework[].class); //vllt. in eine ArrayList packen, besser in JSP
  575. +
  576. + this.session.setAttribute("homework", homework);
  577. + }
  578. +
  579. + public void createHomeworkBySchoolClass(int classId) throws IOException{
  580. + URLConnection connection = new URLConnection();
  581. + String getResponse = connection.get("homework?classid=" + classId);
  582. + Gson g = new GsonBuilder().create();
  583. + Homework[] homework = g.fromJson(getResponse, Homework[].class); //vllt. in eine ArrayList packen, besser in JSP
  584. +
  585. + this.session.setAttribute("homework", homework);
  586. + }
  587. +
  588. + public void createSubjectBean() throws IOException{
  589. + URLConnection connection = new URLConnection();
  590. + String getResponse = connection.get("subject");
  591. + Gson g = new GsonBuilder().create();
  592. + Subject[] subject = g.fromJson(getResponse, Subject[].class); //vllt. in eine ArrayList packen, besser in JSP
  593. +
  594. + this.session.setAttribute("subject", subject);
  595. + }
  596. +
  597. + public void createEventsBeanBySchoolId(int schoolId) throws IOException{
  598. + URLConnection connection = new URLConnection();
  599. + String getResponse = connection.get("event?schoolid=" + schoolId);
  600. + Gson g = new GsonBuilder().create();
  601. + Event[] events = g.fromJson(getResponse, Event[].class); //vllt. in eine ArrayList packen, besser in JSP
  602. +
  603. + this.session.setAttribute("events", events);
  604. + }
  605. +
  606. +}
  607. diff --git a/src/java/misc/URLConnection.java b/src/java/misc/URLConnection.java
  608. index a654156..c849bb1 100644
  609. --- a/src/java/misc/URLConnection.java
  610. +++ b/src/java/misc/URLConnection.java
  611. @@ -7,10 +7,6 @@ import java.io.InputStreamReader;
  612. import java.net.HttpURLConnection;
  613. import java.net.URL;
  614.  
  615. -
  616. -/**
  617. - * Created by Matze on 12.07.2017.
  618. - */
  619. public class URLConnection {
  620.  
  621. private final String baseUrl;
  622. diff --git a/src/java/servlets/ChangerServlet.java b/src/java/servlets/ChangerServlet.java
  623. new file mode 100644
  624. index 0000000..6f1b581
  625. --- /dev/null
  626. +++ b/src/java/servlets/ChangerServlet.java
  627. @@ -0,0 +1,33 @@
  628. +package servlets;
  629. +
  630. +import java.io.IOException;
  631. +import javax.servlet.ServletException;
  632. +import javax.servlet.annotation.WebServlet;
  633. +import javax.servlet.http.HttpServlet;
  634. +import javax.servlet.http.HttpServletRequest;
  635. +import javax.servlet.http.HttpServletResponse;
  636. +import misc.BeanChanger;
  637. +
  638. +@WebServlet(name = "ChangerServlet", urlPatterns = {"/ChangerServlet"})
  639. +public class ChangerServlet extends HttpServlet {
  640. +
  641. +
  642. + protected void doTheStuff(HttpServletRequest request, HttpServletResponse response)
  643. + throws ServletException, IOException {
  644. +
  645. + BeanChanger beanChanger = new BeanChanger(request, response);
  646. + //wenn changes auf beans dann hier is the way to go
  647. + }
  648. +
  649. + @Override
  650. + protected void doPost(HttpServletRequest request, HttpServletResponse response)
  651. + throws ServletException, IOException {
  652. + doTheStuff(request, response);
  653. + }
  654. +
  655. + @Override
  656. + protected void doGet(HttpServletRequest request, HttpServletResponse response)
  657. + throws ServletException, IOException {
  658. + doPost(request, response);
  659. + }
  660. +}
  661. diff --git a/src/java/servlets/LoginServlet.java b/src/java/servlets/LoginServlet.java
  662. index 10d3a09..302584b 100644
  663. --- a/src/java/servlets/LoginServlet.java
  664. +++ b/src/java/servlets/LoginServlet.java
  665. @@ -1,8 +1,5 @@
  666. package servlets;
  667.  
  668. -import beans.Teacher;
  669. -import com.google.gson.Gson;
  670. -import com.google.gson.GsonBuilder;
  671. import misc.URLConnection;
  672.  
  673. import javax.servlet.ServletException;
  674. @@ -11,10 +8,8 @@ import javax.servlet.http.HttpServlet;
  675. import javax.servlet.http.HttpServletRequest;
  676. import javax.servlet.http.HttpServletResponse;
  677. import java.io.IOException;
  678. -
  679. -/**
  680. - * Created by Matze on 11.07.2017.
  681. - */
  682. +import javax.servlet.RequestDispatcher;
  683. +import misc.BeanFiller;
  684.  
  685. @WebServlet(urlPatterns = {"/LoginServlet"})
  686. public class LoginServlet extends HttpServlet {
  687. @@ -24,19 +19,39 @@ public class LoginServlet extends HttpServlet {
  688. String username = request.getParameter("username");
  689. String password = request.getParameter("password");
  690. String type = request.getParameter("type");
  691. -
  692. +
  693. + BeanFiller beanfiller = new BeanFiller(request,response);
  694. String json = "{username: " + username + ", password: " + password + ", type: " + type + "}";
  695. -
  696. - URLConnection connection = new URLConnection();
  697. - String postResponse = connection.post("login", json);
  698. -
  699. - if (postResponse.length() > 3){
  700. - response.getWriter().print("login successful");
  701. - Gson g = new GsonBuilder().create();
  702. - request.setAttribute(type, g.fromJson(postResponse,Teacher[].class)); //muss hier noch geändert werden damit allgemeingültig!
  703. +
  704. + if (checkLogin(json)){
  705. +
  706. + switch (type) {
  707. + case "teacher":
  708. + beanfiller.fillTeacherBeans(json);
  709. + break;
  710. + case "child":
  711. + beanfiller.fillChildBeans(json);
  712. + break;
  713. + case "parent":
  714. + beanfiller.fillParentBeans(json);
  715. + break;
  716. + case "schooladmin":
  717. + beanfiller.fillSchoolAdminBeans(json);
  718. + break;
  719. + case "ministerium":
  720. + beanfiller.fillMinisteriumBeans(json);
  721. + break;
  722. + default:
  723. + beanfiller.fail();
  724. + break;
  725. + }
  726. +
  727. + RequestDispatcher dispatcher = request.getRequestDispatcher("/jsp/home.jsp");
  728. + dispatcher.forward(request, response);
  729. }
  730. - else
  731. + else{
  732. response.getWriter().print("login fehlgeschlagen");
  733. + }
  734. }
  735.  
  736. @Override
  737. @@ -48,4 +63,11 @@ public class LoginServlet extends HttpServlet {
  738. protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  739. doPost(request, response);
  740. }
  741. +
  742. + public boolean checkLogin(String json) throws IOException, ServletException{
  743. + URLConnection connection = new URLConnection();
  744. + String postResponse = connection.post("login", json);
  745. + return postResponse.length() > 3;
  746. + }
  747. +
  748. }
  749. diff --git a/src/java/servlets/SchoolClassSwitcher.java b/src/java/servlets/SchoolClassSwitcher.java
  750. new file mode 100644
  751. index 0000000..4ec8781
  752. --- /dev/null
  753. +++ b/src/java/servlets/SchoolClassSwitcher.java
  754. @@ -0,0 +1,35 @@
  755. +package servlets;
  756. +
  757. +import java.io.IOException;
  758. +import javax.servlet.RequestDispatcher;
  759. +import javax.servlet.ServletException;
  760. +import javax.servlet.annotation.WebServlet;
  761. +import javax.servlet.http.HttpServlet;
  762. +import javax.servlet.http.HttpServletRequest;
  763. +import javax.servlet.http.HttpServletResponse;
  764. +import misc.BeanFiller;
  765. +
  766. +@WebServlet(name = "SchoolClassSwitcher", urlPatterns = {"/SchoolClassSwitcher"})
  767. +public class SchoolClassSwitcher extends HttpServlet {
  768. +
  769. + protected void processRequest(HttpServletRequest request, HttpServletResponse response)
  770. + throws ServletException, IOException {
  771. + int schoolId = (Integer) Integer.parseInt(request.getParameter("schoolClassButton"));
  772. + BeanFiller beanfiller = new BeanFiller(request, response);
  773. + beanfiller.createSpecificPupilBeanForSchoolClass(schoolId);
  774. + RequestDispatcher dispatcher = request.getRequestDispatcher("/jsp/klassen.jsp");
  775. + dispatcher.forward(request, response);
  776. + }
  777. +
  778. + @Override
  779. + protected void doGet(HttpServletRequest request, HttpServletResponse response)
  780. + throws ServletException, IOException {
  781. + processRequest(request, response);
  782. + }
  783. +
  784. + @Override
  785. + protected void doPost(HttpServletRequest request, HttpServletResponse response)
  786. + throws ServletException, IOException {
  787. + processRequest(request, response);
  788. + }
  789. +}
  790. diff --git a/src/java/servlets/SiteSwitcher.java b/src/java/servlets/SiteSwitcher.java
  791. new file mode 100644
  792. index 0000000..ff28eaf
  793. --- /dev/null
  794. +++ b/src/java/servlets/SiteSwitcher.java
  795. @@ -0,0 +1,77 @@
  796. +package servlets;
  797. +
  798. +import java.io.IOException;
  799. +import java.sql.SQLException;
  800. +import javax.servlet.RequestDispatcher;
  801. +import javax.servlet.ServletException;
  802. +import javax.servlet.annotation.WebServlet;
  803. +import javax.servlet.http.HttpServlet;
  804. +import javax.servlet.http.HttpServletRequest;
  805. +import javax.servlet.http.HttpServletResponse;
  806. +
  807. +
  808. +@WebServlet(urlPatterns = {"/SiteSwitcher"})
  809. +public class SiteSwitcher extends HttpServlet {
  810. +
  811. + protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws SQLException, ServletException, IOException {
  812. + //checkForLoggedIn(request, response);
  813. + String action = request.getParameter("klick");
  814. + String site;
  815. + switch(action){
  816. + case "events":
  817. + site = "/jsp/events.jsp";
  818. + break;
  819. + case "home":
  820. + site = "/jsp/home.jsp";
  821. + break;
  822. + case "klassen":
  823. + site = "/jsp/klassen.jsp";
  824. + break;
  825. + case "nachrichten":
  826. + site = "/jsp/nachrichten.jsp";
  827. + break;
  828. + case "hausaufgaben":
  829. + site = "/jsp/hausaufgaben.jsp";
  830. + break;
  831. + case "logout":
  832. + request.getSession().invalidate();
  833. + site = "/index.jsp";
  834. + break;
  835. + default:
  836. + site = "/jsp/home.jsp";
  837. + break;
  838. + }
  839. +
  840. + RequestDispatcher dispatcher = request.getRequestDispatcher(site);
  841. + dispatcher.forward(request, response);
  842. + }
  843. +
  844. + @Override
  845. + protected void doGet(HttpServletRequest request, HttpServletResponse response)
  846. + throws ServletException, IOException {
  847. + try {
  848. + processRequest(request, response);
  849. + } catch (SQLException ex) {
  850. + // do something
  851. + }
  852. + }
  853. +
  854. + @Override
  855. + protected void doPost(HttpServletRequest request, HttpServletResponse response)
  856. + throws ServletException, IOException {
  857. + try {
  858. + processRequest(request, response);
  859. + } catch (SQLException ex) {
  860. + // do something
  861. + }
  862. + }
  863. +
  864. +// private void checkForLoggedIn(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  865. +// HttpSession session = request.getSession();
  866. +// UserBean ubean = (UserBean) session.getAttribute("user");
  867. +// if (ubean == null) {
  868. +// RequestDispatcher dispatcher = request.getRequestDispatcher("/index.jsp");
  869. +// dispatcher.forward(request, response);
  870. +// }
  871. +// }
  872. +}
  873. \ No newline at end of file
  874. diff --git a/web/css/style.css b/web/css/style.css
  875. new file mode 100644
  876. index 0000000..0a04fdd
  877. --- /dev/null
  878. +++ b/web/css/style.css
  879. @@ -0,0 +1,98 @@
  880. +#menuBar{
  881. + border-style: solid;
  882. + border-width: 1px;
  883. + border-color: black;
  884. + text-align: center;
  885. + padding-top: 15px;
  886. +}
  887. +
  888. +.inhaltTop{
  889. + border-style: solid;
  890. + border-width: 1px;
  891. + border-color: black;
  892. + text-align: center;
  893. + padding-top: 15px;
  894. + padding-bottom: 15px;
  895. + margin-top: 10px;
  896. +}
  897. +
  898. +.homeBottomHausaufgaben{
  899. + width: 45%;
  900. + border-style: solid;
  901. + border-width: 1px;
  902. + border-color: black;
  903. + padding-top: 15px;
  904. + margin-top: 10px;
  905. + margin-left: 30px;
  906. + text-align: center;
  907. + margin-right: 20px;
  908. + float: left;
  909. +}
  910. +
  911. +.homeBottomEvents{
  912. + width: 45%;
  913. + border-style: solid;
  914. + border-width: 1px;
  915. + border-color: black;
  916. + padding-top: 15px;
  917. + margin-top: 10px;
  918. + text-align: center;
  919. + float: left;
  920. +}
  921. +
  922. +.klassenBottomSchueler{
  923. + width: 20%;
  924. + border-style: solid;
  925. + border-width: 1px;
  926. + border-color: black;
  927. + padding-top: 15px;
  928. + margin-top: 10px;
  929. + margin-right: 20px;
  930. + margin-left: 20px;
  931. + text-align: center;
  932. + float: left;
  933. +}
  934. +
  935. +.klassenBottomNachrichten{
  936. + width: 20%;
  937. + border-style: solid;
  938. + border-width: 1px;
  939. + border-color: black;
  940. + padding-top: 15px;
  941. + margin-top: 10px;
  942. + margin-right: 20px;
  943. + text-align: center;
  944. + float: left;
  945. +}
  946. +
  947. +.klassenBottomHausaufgaben{
  948. + width: 25%;
  949. + border-style: solid;
  950. + border-width: 1px;
  951. + border-color: black;
  952. + padding-top: 15px;
  953. + margin-top: 10px;
  954. + margin-right: 20px;
  955. + text-align: center;
  956. + float: left;
  957. +}
  958. +
  959. +.klassenBottomEvents{
  960. + width: 25%;
  961. + border-style: solid;
  962. + border-width: 1px;
  963. + border-color: black;
  964. + padding-top: 15px;
  965. + margin-top: 10px;
  966. + text-align: center;
  967. + float: left;
  968. +}
  969. +
  970. +.event{
  971. + border-style: solid;
  972. + border-width: 2px;
  973. + border-color: green;
  974. + text-align: center;
  975. + margin-bottom: 10px;
  976. + float: inside;
  977. +}
  978. \ No newline at end of file
  979. diff --git a/web/jsp/events.jsp b/web/jsp/events.jsp
  980. new file mode 100644
  981. index 0000000..907f2c1
  982. --- /dev/null
  983. +++ b/web/jsp/events.jsp
  984. @@ -0,0 +1,27 @@
  985. +<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt" %>
  986. +<%@ page language="Java" contentType="text/html" pageEncoding="UTF-8" %>
  987. +<html lang="de">
  988. + <head>
  989. + <meta charset="utf-8">
  990. + <meta name="viewport" content="width=device-width, initial-scale=1.0">
  991. + <link rel="stylesheet" href="<%= request.getContextPath()%>/css/style.css">
  992. + <title>Events</title>
  993. + </head>
  994. +
  995. +
  996. + <body>
  997. +
  998. + <%@ include file="header.jspf" %>
  999. +
  1000. + <div class="inhalt">
  1001. +
  1002. + Das ist die Events-Seite
  1003. +
  1004. + </div>
  1005. +
  1006. + <footer>
  1007. +
  1008. + </footer>
  1009. +
  1010. + </body>
  1011. +</html>
  1012. \ No newline at end of file
  1013. diff --git a/web/jsp/hausaufgaben.jsp b/web/jsp/hausaufgaben.jsp
  1014. new file mode 100644
  1015. index 0000000..f6c3120
  1016. --- /dev/null
  1017. +++ b/web/jsp/hausaufgaben.jsp
  1018. @@ -0,0 +1,27 @@
  1019. +<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt" %>
  1020. +<%@ page language="Java" contentType="text/html" pageEncoding="UTF-8" %>
  1021. +<html lang="de">
  1022. + <head>
  1023. + <meta charset="utf-8">
  1024. + <meta name="viewport" content="width=device-width, initial-scale=1.0">
  1025. + <link rel="stylesheet" href="<%= request.getContextPath()%>/css/style.css">
  1026. + <title>Hausaufgaben</title>
  1027. + </head>
  1028. +
  1029. +
  1030. + <body>
  1031. +
  1032. + <%@ include file="header.jspf" %>
  1033. +
  1034. + <div class="inhalt">
  1035. +
  1036. + Das ist die Hausaufgaben-Seite
  1037. +
  1038. + </div>
  1039. +
  1040. + <footer>
  1041. +
  1042. + </footer>
  1043. +
  1044. + </body>
  1045. +</html>
  1046. \ No newline at end of file
  1047. diff --git a/web/jsp/header.jspf b/web/jsp/header.jspf
  1048. new file mode 100644
  1049. index 0000000..6f63608
  1050. --- /dev/null
  1051. +++ b/web/jsp/header.jspf
  1052. @@ -0,0 +1,17 @@
  1053. +<%
  1054. + if (session.getAttribute("user") == null) {
  1055. + request.getRequestDispatcher("/index.jsp").forward(request, response);
  1056. + }
  1057. +%>
  1058. +<header>
  1059. + <div id="menuBar">
  1060. + <form action="SiteSwitcher" method="post">
  1061. + <button type="submit" name="klick" value="events" id="eventseite" class="menuebutton">Events</button>
  1062. + <button type="submit" name="klick" value="hausaufgaben" id="hausaufgabenseite" class="menuebutton">Hausaufgaben</button>
  1063. + <button type="submit" name="klick" value="home" id="homeseite" class="menuebutton">Home</button>
  1064. + <button type="submit" name="klick" value="klassen" id="klassenseite" class="menuebutton">Klassen</button>
  1065. + <button type="submit" name="klick" value="nachrichten" id="nachrichtenseite" class="menuebutton">Nachrichten</button>
  1066. + <button type="submit" name="klick" value="logout" id="logoutseite" class="menuebutton">Logout</button>
  1067. + </form>
  1068. + </div>
  1069. +</header>
  1070. \ No newline at end of file
  1071. diff --git a/web/jsp/home.jsp b/web/jsp/home.jsp
  1072. new file mode 100644
  1073. index 0000000..79505d9
  1074. --- /dev/null
  1075. +++ b/web/jsp/home.jsp
  1076. @@ -0,0 +1,65 @@
  1077. +<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt" %>
  1078. +<%@ page language="Java" contentType="text/html" pageEncoding="UTF-8" %>
  1079. +<html lang="de">
  1080. + <head>
  1081. + <meta charset="utf-8">
  1082. + <meta name="viewport" content="width=device-width, initial-scale=1.0">
  1083. + <link rel="stylesheet" href="<%= request.getContextPath()%>/css/style.css">
  1084. + <title>Home</title>
  1085. + </head>
  1086. +
  1087. +
  1088. + <body>
  1089. +
  1090. + <%@ include file="header.jspf" %>
  1091. +
  1092. + <div class="inhaltTop">
  1093. + Das ist die Home-Seite
  1094. + <br>
  1095. + <br>
  1096. + Willkommen (${user.object.firstname} ${user.object.lastname}) der Schule (${user.object.school.name})
  1097. + </div>
  1098. +
  1099. + <div class="homeBottomHausaufgaben">
  1100. + Alle von Ihnen aufgegebene Hausaufgaben:
  1101. + <br>
  1102. + <br>
  1103. + Abgabedatum:
  1104. + <input type="date" id="abgabe" name="abgabe" required pattern="[0-9]{2}.[0-9]{2}.[0-9]{4}">
  1105. + <br>
  1106. + Erstellungsdatum:
  1107. + <input type="date" id="erstellung" name="erstellung" required pattern="[0-9]{2}.[0-9]{2}.[0-9]{4}">
  1108. + <br>
  1109. + <br>
  1110. + <c:forEach items="${homework}" var="homework">
  1111. + <div class="event">
  1112. + ${homework.schoolclass.name}
  1113. + <br>
  1114. + ${homework.homework}
  1115. + </div>
  1116. + <br>
  1117. + </c:forEach>
  1118. + </div>
  1119. +
  1120. + <div class="homeBottomEvents">
  1121. + Alle anstehenden Events:
  1122. + <br>
  1123. + <br>
  1124. + <c:forEach items="${events}" var="event">
  1125. + <div class="event">
  1126. + ${event.title}
  1127. + <br>
  1128. + ${event.description}
  1129. + <br>
  1130. + ${event.schooldate}
  1131. + </div>
  1132. + <br>
  1133. + </c:forEach>
  1134. + </div>
  1135. +
  1136. + <footer>
  1137. +
  1138. + </footer>
  1139. +
  1140. + </body>
  1141. +</html>
  1142. \ No newline at end of file
  1143. diff --git a/web/jsp/klassen.jsp b/web/jsp/klassen.jsp
  1144. new file mode 100644
  1145. index 0000000..38a0817
  1146. --- /dev/null
  1147. +++ b/web/jsp/klassen.jsp
  1148. @@ -0,0 +1,70 @@
  1149. +<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt" %>
  1150. +<%@ page language="Java" contentType="text/html" pageEncoding="UTF-8" %>
  1151. +<html lang="de">
  1152. + <head>
  1153. + <meta charset="utf-8">
  1154. + <meta name="viewport" content="width=device-width, initial-scale=1.0">
  1155. + <link rel="stylesheet" href="<%= request.getContextPath()%>/css/style.css">
  1156. + <title>Klassen</title>
  1157. + </head>
  1158. +
  1159. + <body>
  1160. +
  1161. + <%@ include file="header.jspf" %>
  1162. +
  1163. + <div class="inhaltTop">
  1164. + Das ist die Klassen-Seite
  1165. + <button type="submit" name="klick" value="events" id="eventseite" class="menuebutton">Klasse hinzufügen</button>
  1166. + <br>
  1167. + <br>
  1168. + <form name="schoolClassAuswahl" action="SchoolClassSwitcher" method="post">
  1169. + <c:forEach items="${schoolclass}" var="class">
  1170. + <button name="schoolClassButton" value="${class.id}">${class.name}</button>
  1171. + </c:forEach>
  1172. + </form>
  1173. + </div>
  1174. +
  1175. + <c:if test="${!empty pupils}">
  1176. + <div class="klassenBottomSchueler">
  1177. + Schüler der Klasse (${pupils[0].schoolclass.name}):
  1178. + <br>
  1179. + <br>
  1180. + <c:forEach items="${pupils}" var="pupil">
  1181. + <label>
  1182. + <input type="checkbox" name="pupil" value="${pupil.id}">
  1183. + ${pupil.firstname} , ${pupil.lastname}
  1184. + </label>
  1185. + <br>
  1186. + </c:forEach>
  1187. + </div>
  1188. +
  1189. + <div class="klassenBottomNachrichten">
  1190. + Nachrichten oder Fehlzeiten:
  1191. + <br>
  1192. + <br>
  1193. + <button type="submit" name="klick" value="events" id="eventseite" class="menuebutton">Nachricht an die Eltern</button>
  1194. + <br>
  1195. + <button type="submit" name="klick" value="hausaufgaben" id="hausaufgabenseite" class="menuebutton">Fehlzeiten eintragen</button>
  1196. + </div>
  1197. +
  1198. + <div class="klassenBottomHausaufgaben">
  1199. + Hausaufgaben:
  1200. + <br>
  1201. + <br>
  1202. + <button type="submit" name="klick" value="events" id="eventseite" class="menuebutton">Hausaufgabe hinzufügen</button>
  1203. + </div>
  1204. +
  1205. + <div class="klassenBottomEvents">
  1206. + Events:
  1207. + <br>
  1208. + <br>
  1209. + <button type="submit" name="klick" value="events" id="eventseite" class="menuebutton">Event hinzufügen</button>
  1210. + </div>
  1211. + </c:if>
  1212. +
  1213. + <footer>
  1214. +
  1215. + </footer>
  1216. +
  1217. + </body>
  1218. +</html>
  1219. \ No newline at end of file
  1220. diff --git a/web/jsp/nachrichten.jsp b/web/jsp/nachrichten.jsp
  1221. new file mode 100644
  1222. index 0000000..c97a71c
  1223. --- /dev/null
  1224. +++ b/web/jsp/nachrichten.jsp
  1225. @@ -0,0 +1,27 @@
  1226. +<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt" %>
  1227. +<%@ page language="Java" contentType="text/html" pageEncoding="UTF-8" %>
  1228. +<html lang="de">
  1229. + <head>
  1230. + <meta charset="utf-8">
  1231. + <meta name="viewport" content="width=device-width, initial-scale=1.0">
  1232. + <link rel="stylesheet" href="<%= request.getContextPath()%>/css/style.css">
  1233. + <title>Nachrichten</title>
  1234. + </head>
  1235. +
  1236. +
  1237. + <body>
  1238. +
  1239. + <%@ include file="header.jspf" %>
  1240. +
  1241. + <div class="inhalt">
  1242. +
  1243. + Das ist die Nachrichten-Seite
  1244. +
  1245. + </div>
  1246. +
  1247. + <footer>
  1248. +
  1249. + </footer>
  1250. +
  1251. + </body>
  1252. +</html>
  1253. \ No newline at end of file
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement