EXtreme Programming XP Тема 11. XP Для работы по администрированию таблицы Department создаем классы: DepartmentListController; EnterDepartmentController;

Slides:



Advertisements
Similar presentations
Servlets & JSPs - Sharad Ballepu.
Advertisements

.meetup.com/13 Example application.
J0 1 Marco Ronchetti - Basi di Dati Web e Distribuite – Laurea Specialitica in Informatica – Università di Trento.
JSP and Servelets.
CGI programming. Common Gateway Interface interface between web server and other programs (cgi scripts) information passed as environment variables passed.
Struts Portlet Adding an Action Copyright © Liferay, Inc. All Rights Reserved. No material may be reproduced electronically or in print without.
Sequence of characters Generalized form Expresses Pattern of strings in a Generalized notation.
EXtreme Programming XP Тема 8. XP Объектно-реляционное связывание позволяет связать реляционную базу данных и простые объекты Java. Обычно связывание.
Servlets, JSP and JavaBeans Joshua Scotton.  Getting Started  Servlets  JSP  JavaBeans  MVC  Conclusion.
JLab Lattice Portal – Data Grid Web Service Ying Chen, Chip Watson Thomas Jefferson National Accelerator Facility.
Dispatching, monitoring, filtering
Exercises of the Tutorial on Advanced Web Programming Authors: Miroslava Mitrovic Dragan Milicev Nino.
Cookie in a servlet. Cookies are small bits of textual information that a Web server sends to a browser and that the browser returns unchanged when visiting.
Exceptions Session 21. Memory Upload Creating Exceptions Using exceptions to control object creation and validation.
Agile Java Development
1 Servlets Based on Notes by Dave Hollinger & Ethan Cerami Also, the Online Java Tutorial by Sun.
Web Development with Karsten Schulz Terp-Nielsen Master Principal Sales Consultant Oracle Denmark.
Java Server Pages (JSP)
EXtreme Programming XP Тема 10. XP 1. Контроллеры (SimpleFormController, UrlFilenameViewController); 2. Модель и представление соединяются посредством.
 2002 Prentice Hall. All rights reserved. Chapter 9: Servlets Outline 9.1 Introduction 9.2 Servlet Overview and Architecture Interface Servlet and.
 2003 Prentice Hall, Inc. All rights reserved. Chapter 24: Servlets Outline 24.1 Introduction 24.2 Servlet Overview and Architecture Interface.
METHOD OVERRIDING Sub class can override the methods defined by the super class. Overridden Methods in the sub classes should have same name, same signature.
1 Servlets: Leftover Odds and Ends (Most apply to JSPs as well, duh….) Representation and Management of Data on the Internet, 2007 CS Department, HUJI.
Securing web applications using Java EE Dr Jim Briggs 1.
Web MVC-2: Apache Struts Rimon Mikhaiel
Objectives Ch. D - 1 At the end of this chapter students will: Know the general architecture and purpose of servlets Understand how to create a basic servlet.
2/16/2004 Dynamic Content February 16, /16/2004 Assignments Due – Message of the Day Part 1 Due – Reading and Warmup Work on Message of the Day.
An Introduction To the Spring M.V.C. Framework Reference From Website By Tom Kochanowicz.
Servlets Compiled by Dr. Billy B. L. Lim. Servlets Servlets are Java programs which are invoked to service client requests on a Web server. Servlets extend.
Java Enterprise Edition Java Web Development Structure of a web project Introduction to Web Applications The first project Introduction to Java Web Development.
Web Proxy Server. Proxy Server Introduction Returns status and error messages. Handles http CGI requests. –For more information about CGI please refer.
BEST PRACTICES - Java By Configuration Use global-forwards/results Helps to avoid duplicate jsp files and redundancy forward mapping.
Farewell Old Application Server The Server Container Anti- Pattern and how to avoid it.
1 Identifiers  Identifiers are the words a programmer uses in a program  An identifier can be made up of letters, digits, the underscore character (
Examples of Using Servlets and JSP Representation and Management of Data on the Internet.
Chapter 5 Java Servlets. Objectives Explain the nature of a servlet and its operation Use the appropriate servlet methods in a web application Code the.
Java Servlets and Java Server Pages Carol Wolf Computer Science.
Basic Struts Architecture Client Server Database Request Response Control View Model Server Struts Framework.
JSP Architecture Outline  Model 1 Architecture  Model 2 Architecture.
COMP 321 Week 7. Overview HTML and HTTP Basics Dynamic Web Content ServletsMVC Tomcat in Eclipse Demonstration Lab 7-1 Introduction.
Web Application Development * These slides have been adapted and modified from CoreServlets course material (Marty Hall) and LUMS cs391 (Umair Javed).
Mark Dixon 1 09 – Java Servlets. Mark Dixon 2 Session Aims & Objectives Aims –To cover a range of web-application design techniques Objectives, by end.
Chapter 9 Session Tracking. Session Tracking Basics Accessing the session object associated with the current request: Call request.getSession to get an.
Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. Forms with Spring MVC Handling Form.
Java Server Pages (JSP)
Java Server Pages An introduction to JSP. Containers and Components Several clients – one system.
Li Tak Sing COMPS311F. A web page that counts the number of times that you have visited the page. You can try the page at:
Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. Spring MVC Essentials Getting started.
1 Introduction to Servlets. Topics Web Applications and the Java Server. HTTP protocol. Servlets 2.
Mark Dixon 1 11 – Java Servlets. Mark Dixon 2 Session Aims & Objectives Aims –To cover a range of web-application design techniques Objectives, by end.
Access control 2/18/2009. TOMCAT Security Model Declarative Security:  the expression of application security external to the application, and it allows.
CreatingClasses-SlideShow-part31 Creating Classes part 3 Barb Ericson Georgia Institute of Technology Dec 2009.
©SoftMoore ConsultingSlide 1 Filters. Filters can be used in a web application to intercept, examine, and possibly transform requests or responses associated.
Vakgroep Informatietechnologie – Onderzoeksgroep (naam) Web Centric Design of Distributed Software.
Struts Framework Day-2 Ashok Chakravarti. DataSource Usage Sample Struts-config.xml …
Servlets 4 Lec 30 Web Design and Development. Looking Back… Response Redirection  Sending a standard redirect  Sending a redirect to an error page Request.
©SoftMoore ConsultingSlide 1 Overview of Servlets and JavaServer Pages (JSP)
HTTP protocol Java Servlets. HTTP protocol Web system communicates with end-user via HTTP protocol HTTP protocol methods: GET, POST, HEAD, PUT, OPTIONS,
Expect the Unexpected Kito D. Mann Principal Consultant.
The Chain of Responsibility Pattern (Behavioral) ©SoftMoore ConsultingSlide 1.
OOSD Using Java CBTS Framework. 11/2/04CBTS2 Servlet  A servlet is a Java program that can extends Web server’s functionality.  Servlets interact with.
Java Servlets By: Tejashri Udavant..
An Introduction To the Spring M.V.C. Framework
Sessions.
null, true, and false are also reserved.
CS320 Web and Internet Programming Cookies and Session Tracking
Servlet APIs Every servlet must implement javax.servlet.Servlet interface Most servlets implement the interface by extending one of these classes javax.servlet.GenericServlet.
CS288 Lab Exercise 2.
Introduction to Java Servlets
Pre-assessment Questions
Presentation transcript:

eXtreme Programming XP Тема 11

XP Для работы по администрированию таблицы Department создаем классы: DepartmentListController; EnterDepartmentController; DeleteDepartmentController; EnterDepartmentValidator; DelName – командный объект для формы выбора удаляемого элемента; DeleteDepartmentController.

XP Добавляем: <bean name="departmentListController" class="com.visualpatterns.timex.controller.DepartmentListC ontroller"> departmentlist

XP Валидаторы: <bean id="deleteDepartmentValidator" class="com.visualpatterns.timex.controller.DeleteDepa rtmentValidator" /> Менеджер: <bean id="departmentManager" class="com.visualpatterns.timex.model.DepartmentM anager" />

XP <bean name="enterDepartmentConroller" class="com.visualpatterns.timex.controller.EnterDepartmentController"> true /enterdepartment redirect:departmentlist.htm com.visualpatterns.timex.model.Department

XP <bean name="deleteDepartmentConroller" class="com.visualpatterns.timex.controller.DeletDepartmentController"> true /deletedepartment redirect:departmentlist.htm com.visualpatterns.timex.controller.DelName

XP Назначение перехватчика на файлы: <bean id="urlMapAuthenticate" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapp ing"> departmentListController enterDepartmentConroller deleteDepartmentConroller

XP package com.visualpatterns.timex.controller; public class SignLogin { String login, password; public String getLogin() {return login;} public void setLogin(String login){this.login=login;} public String getPassword(){return password;} public void setPassword(String pass){ password=pass;} }

XP public List getDepartments() { List departmentList = null; SessionFactory SessionFactory=new Configuration().configure().buildSessionFactory(); Session session =SessionFactory.getCurrentSession(); session.beginTransaction(); try { departmentList = session.createQuery( "from Department ORDER BY name").list(); session.getTransaction().commit(); } catch (HibernateException e){ session.getTransaction().rollback(); throw e;} return departmentList; }

XP public Department getDepartment(String departmentCode) { Department department = null; SessionFactory SessionFactory=new Configuration().configure().buildSessionFactory(); Session session =SessionFactory.getCurrentSession(); session.beginTransaction(); try{ department = (Department) session.createQuery( "from Department" + " where departmentCode = ?").setString(0, departmentCode).uniqueResult(); session.getTransaction().commit(); SessionFactory.close();} catch (HibernateException e) { session.getTransaction().rollback(); throw e;} return department; }

XP public void saveDepartment(Department department) { SessionFactory SessionFactory=new Configuration().configure().buildSessionFactory(); Session session =SessionFactory.getCurrentSession(); session.beginTransaction(); try{ session.saveOrUpdate(department); session.getTransaction().commit(); SessionFactory.close(); } catch (HibernateException e) { session.getTransaction().rollback(); throw e;} }

XP public void deleteDepartment(String departmentCode) { SessionFactory SessionFactory=new Configuration().configure().buildSessionFactory(); Session session =SessionFactory.getCurrentSession(); session.beginTransaction(); try{ session.delete(session.load(Department.class, departmentCode)); session.flush(); session.getTransaction().commit(); SessionFactory.close();} catch (HibernateException e) { session.getTransaction().rollback(); throw e;} }

XP package com.visualpatterns.timex.controller; import java.util.List; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.mvc.Controller; import com.visualpatterns.timex.model.Department; import com.visualpatterns.timex.model.DepartmentManager; import com.visualpatterns.timex.controller.ApplicationSecurityManager; public class DepartmentListController implements Controller { private DepartmentManager departmentManager; public static final String MAP_KEY = "departments"; private ApplicationSecurityManager applicationSecurityManager; private String successView;

XP public ModelAndView handleRequest( HttpServletRequest request, HttpServletResponse response) throws Exception { List departments = departmentManager.getDepartments(); return new ModelAndView(getSuccessView(), MAP_KEY, departments); } public ApplicationSecurityManager getApplicationSecurityManager() { return applicationSecurityManager; } public void setApplicationSecurityManager(ApplicationSecurityManager app) { applicationSecurityManager=app; }

XP public DepartmentManager getDepartmentManager() { return departmentManager;} public void setDepartmentManager(DepartmentManager departmentManager) { this.departmentManager = departmentManager;} public String getSuccessView() { return successView;} public void setSuccessView(String successView) { this.successView = successView; }

XP package com.visualpatterns.timex.controller; import org.springframework.validation.Errors; import com.visualpatterns.timex.model.Department; public class EnterDepartmentValidator implements org.springframework.validation.Validator { public boolean supports(Class clazz) { return clazz.equals(Department.class);} public void validate(Object command, Errors errors) { Department log = (Department) command; if (log == null) return; String code = log.getDepartmentCode(); if (code.length()>2 || code.length()<2) errors.reject("error.enterdepartment.codeiswrong"); }

XP package com.visualpatterns.timex.controller; import java.util.HashMap; import java.util.Map; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.springframework.validation.BindException; import org.springframework.web.bind.ServletRequestDataBinder; import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.mvc.SimpleFormController; import com.visualpatterns.timex.model.DepartmentManager; import com.visualpatterns.timex.model.Department; import com.visualpatterns.timex.model.DepartmentManager; import com.visualpatterns.timex.controller.ApplicationSecurityManager;

XP public class EnterDepartmentController extends SimpleFormController { private DepartmentManager departmentManager = null; private ApplicationSecurityManager applicationSecurityManager; public static final String TID = "tid"; protected Object formBackingObject(HttpServletRequest request) { if (request.getParameter(TID) != null && request.getParameter(TID).trim().length() > 0) { String code1=""; try{ code1=new String(request.getParameter(TID). trim().getBytes("ISO "),"Cp1251"); } catch(Exception e){} return departmentManager.getDepartment(code1); } Department department = new Department(); return department; }

XP protected ModelAndView onSubmit( HttpServletRequest request, HttpServletResponse response, Object command, BindException errors) { Department department = (Department) command; try{ String code1=new String(department.getDepartmentCode().getBytes("ISO "),"Cp1251"); String name1=new String(department.getName().getBytes("ISO "),"Cp1251"); department.setDepartmentCode(code1);department.setName(name1); } catch(Exception e){} departmentManager.saveDepartment(department); try{ String message=new String(getMessageSourceAccessor().getMessage("message.enterdepartment.sa vesuccess").getBytes("ISO "),"Cp1251"); request.getSession().setAttribute("message",message); } catch(Exception e){} return new ModelAndView(getSuccessView());} // также следует добавить все set и get-методы для свойств класса

XP package com.visualpatterns.timex.controller; import org.springframework.validation.Errors; import com.visualpatterns.timex.controller.SignLogin; public class SignInValidator implements org.springframework.validation.Validator { public boolean supports(Class clazz) { return clazz.equals(SignLogin.class); } public void validate(Object command, Errors errors) { SignLogin log = (SignLogin) command; if (log == null) return; String login = log.getLogin(); String password = log.getPassword(); if (!(login.equals("admin") && password.equals("admin"))) errors.reject("error.login.invalid"); }

XP package com.visualpatterns.timex.controller; import org.springframework.validation.Errors; import com.visualpatterns.timex.controller.DelName; public class DeleteDepartmentValidator implements org.springframework.validation.Validator { public boolean supports(Class clazz) { return clazz.equals(DelName.class);} public void validate(Object command, Errors errors) { DelName log = (DelName) command; if (log == null) return; String code = log.getCode(); if (code.length()!=2) errors.reject("error.login.invalid"); }

XP package com.visualpatterns.timex.controller; import java.util.HashMap; import java.util.Map; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.springframework.validation.BindException; import org.springframework.web.bind.ServletRequestDataBinder; import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.mvc.SimpleFormController; import com.visualpatterns.timex.model.DepartmentManager; import com.visualpatterns.timex.model.Department; import com.visualpatterns.timex.controller.DelName; import com.visualpatterns.timex.controller.ApplicationSecurityManager;

XP public class DeletDepartmentController extends SimpleFormController { private DepartmentManager departmentManager = null; private ApplicationSecurityManager applicationSecurityManager; protected Object formBackingObject(HttpServletRequest request) { return new DelName(); } protected Map referenceData(HttpServletRequest request) throws Exception { // для создания списка выбора HashMap model = new HashMap(); model.put("departments", departmentManager.getDepartments()); return model; }

XP protected ModelAndView onSubmit( HttpServletRequest request, HttpServletResponse response, Object command, BindException errors) { DelName code= (DelName) command; String code1=""; try{ code1=new String(code.getCode().getBytes("ISO "),"Cp1251"); }catch(Exception e){} departmentManager.deleteDepartment(code1); request.getSession().setAttribute("message",getMessageSourceAccessor(). getMessage("message.deletedepartment.deletesuccess")); return new ModelAndView(getSuccessView()); } // а также get и set-методы для всех свойств контроллера

XP Список всех отделов Список всех отделов Выйти из системы

XP Добавить отдел Удалить отдел Code Name '>

XP Добавление/редактирование отдела Информация об отделе Выйти из системы

XP Код отдела Название отдела ' value=' ' type="text" size="4" maxlength="6"> ' value=' ' type="text" size="4" maxlength="6“>

XP <input name="cancel" type="button" value="Cancel" onClick="javascript:window.location='departmentlist.htm'">

XP Удаление отдела Выберите отдел для удаления Выйти из системы '> '>

XP <input name="cancel" type="button" value="Cancel" onClick="javascript:window.location='departmentlist.htm'">