{"id":287153,"date":"2017-05-31T17:55:03","date_gmt":"2017-05-31T13:55:03","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=287153"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=287153","title":{"rendered":"Hibernate+jsp \u043f\u0440\u0438 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0435 \u0441\u0435\u0440\u0432\u043b\u0435\u0442\u043e\u0432"},"content":{"rendered":"<p>\u0412\u0441\u0435\u043c \u043f\u0440\u0438\u0432\u0435\u0442!<br \/>  \u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443 \u043e \u0442\u043e\u043c, \u043a\u0430\u043a \u0441\u0432\u044f\u0437\u0430\u0442\u044c JSP \u0441 Hibernate \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u0441\u0435\u0440\u0432\u043b\u0435\u0442\u0430. \u042f \u043d\u0430\u0434\u0435\u044e\u0441\u044c, \u0447\u0442\u043e \u0432\u044b \u0443\u043c\u0435\u0435\u0442\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 Hibernate, \u0435\u0441\u043b\u0438 \u0436\u0435 \u043d\u0435\u0442, \u0442\u043e \u043d\u0430\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u044e \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u044d\u0442\u0443 <a href=\"https:\/\/habrahabr.ru\/post\/320542\/\">\u0441\u0442\u0430\u0442\u044c\u044e<\/a>. \u0422\u0430\u043a\u0436\u0435 \u044f \u043d\u0430\u0434\u0435\u044e\u0441\u044c, \u0447\u0442\u043e \u0432\u044b \u0437\u043d\u0430\u043a\u043e\u043c\u044b \u0441 \u0441\u0435\u0440\u0432\u043b\u0435\u0442\u0430\u043c\u0438 \u0438 \u0445\u043e\u0442\u044c \u0440\u0430\u0437 \u0438\u0445 \u0443\u0441\u043f\u0435\u0448\u043d\u043e \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u043b\u0438. <br \/>  \u0414\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0443 \u0432\u0430\u0441 \u0431\u044b\u043b\u0430 \u0442\u0430\u043a\u0430\u044f \u0436\u0435 \u0431\u0430\u0437\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 MySQL, \u0432\u0441\u0442\u0430\u0432\u044c\u0442\u0435 \u0442\u0443\u0434\u0430 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043a\u043e\u0434:<br \/>  CREATE SCHEMA `hero`;<\/p>\n<p>  CREATE TABLE `hero`.`heroes`<br \/>  (<br \/>  `idhero` INT NOT NULL AUTO_INCREMENT,<br \/>  `name` VARCHAR(45) NOT NULL,<br \/>  PRIMARY KEY (`idhero`));<br \/>  \u0421\u043e\u0437\u0434\u0430\u0451\u043c maven \u043f\u0440\u043e\u0435\u043a\u0442 \u0438 \u0432\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u0438 \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e:<br \/>  <a name=\"habracut\"><\/a>  <\/p>\n<pre><code class=\"xml\">&lt;packaging&gt;war&lt;\/packaging&gt; &lt;properties&gt; &lt;hibernate.version&gt;4.3.5.Final&lt;\/hibernate.version&gt; &lt;\/properties&gt; &lt;dependencies&gt; &lt;dependency&gt; &lt;groupId&gt;javax.servlet&lt;\/groupId&gt; &lt;artifactId&gt;servlet-api&lt;\/artifactId&gt; &lt;version&gt;3.0-alpha-1&lt;\/version&gt; &lt;scope&gt;provided&lt;\/scope&gt; &lt;\/dependency&gt; &lt;dependency&gt; &lt;groupId&gt;commons-fileupload&lt;\/groupId&gt; &lt;artifactId&gt;commons-fileupload&lt;\/artifactId&gt; &lt;version&gt;1.2.2&lt;\/version&gt; &lt;\/dependency&gt; &lt;dependency&gt; &lt;groupId&gt;commons-io&lt;\/groupId&gt; &lt;artifactId&gt;commons-io&lt;\/artifactId&gt; &lt;version&gt;2.4&lt;\/version&gt; &lt;\/dependency&gt; &lt;dependency&gt; &lt;groupId&gt;org.hibernate&lt;\/groupId&gt; &lt;artifactId&gt;hibernate-core&lt;\/artifactId&gt; &lt;version&gt;${hibernate.version}&lt;\/version&gt; &lt;\/dependency&gt; &lt;dependency&gt; &lt;groupId&gt;org.hibernate&lt;\/groupId&gt; &lt;artifactId&gt;hibernate-entitymanager&lt;\/artifactId&gt; &lt;version&gt;${hibernate.version}&lt;\/version&gt; &lt;\/dependency&gt; &lt;dependency&gt; &lt;groupId&gt;javaee&lt;\/groupId&gt; &lt;artifactId&gt;javaee-api&lt;\/artifactId&gt; &lt;version&gt;5&lt;\/version&gt; &lt;\/dependency&gt; &lt;dependency&gt; &lt;groupId&gt;mysql&lt;\/groupId&gt; &lt;artifactId&gt;mysql-connector-java&lt;\/artifactId&gt; &lt;version&gt;5.1.38&lt;\/version&gt; &lt;\/dependency&gt; &lt;dependency&gt; &lt;groupId&gt;javax&lt;\/groupId&gt; &lt;artifactId&gt;javaee-web-api&lt;\/artifactId&gt; &lt;version&gt;6.0&lt;\/version&gt; &lt;scope&gt;provided&lt;\/scope&gt; &lt;\/dependency&gt; &lt;!\u2014 https:\/\/mvnrepository.com\/artifact\/org.apache.commons.. \u2014&gt; &lt;dependency&gt; &lt;groupId&gt;org.apache.commons&lt;\/groupId&gt; &lt;artifactId&gt;commons-lang3&lt;\/artifactId&gt; &lt;version&gt;3.4&lt;\/version&gt; &lt;\/dependency&gt; &lt;dependency&gt; &lt;groupId&gt;jstl&lt;\/groupId&gt; &lt;artifactId&gt;jstl&lt;\/artifactId&gt; &lt;version&gt;1.2&lt;\/version&gt; &lt;\/dependency&gt; &lt;\/dependencies&gt; <\/code><\/pre>\n<p>  \u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u043c\u0441\u044f \u043a \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445. \u041e\u043f\u044f\u0442\u044c \u0436\u0435: \u0435\u0441\u043b\u0438 \u0432\u044b \u043d\u0435 \u0437\u043d\u0430\u0435\u0442\u0435, \u043a\u0430\u043a \u044d\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442\u0441\u044f, \u0442\u043e \u0441\u0442\u0430\u0442\u044c\u044f \u043e\u0431 \u044d\u0442\u043e\u043c \u0438 \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0432\u044b\u0448\u0435.<br \/>  \u0417\u0430\u0442\u0435\u043c \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u043c web \u043c\u043e\u0434\u0443\u043b\u044c.<br \/>  \u0417\u0430\u0445\u043e\u0434\u0438\u043c \u0432 File,Project Structure \u0432\u043a\u043b\u0430\u0434\u043a\u0430 modules. \u041f\u0435\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0443\u0434\u0430\u043b\u0438\u0442\u0435 \u0432\u0441\u0451, \u0447\u0442\u043e \u0435\u0441\u0442\u044c \u0432\u043e \u0432\u043a\u043b\u0430\u0434\u043a\u0435 modules(\u0435\u0441\u043b\u0438 \u043e\u043d\u043e \u0442\u0430\u043c \u0435\u0441\u0442\u044c) \u043d\u0430\u0436\u0430\u0432 \u043d\u0430 -(\u043a\u0440\u0430\u0441\u043d\u0435\u043d\u044c\u043a\u0438\u0439).\u041d\u0430\u0436\u0438\u043c\u0430\u0435\u0442\u0435 \u043d\u0430 +(\u0437\u0435\u043b\u0451\u043d\u044b\u0439)<br \/>  \u0438 \u0434\u043e\u0431\u0430\u0432\u044c\u0442\u0435 web \u043c\u043e\u0434\u0443\u043b\u044c<br \/>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/web\/eda\/325\/70a\/eda32570a2404d8680a4358a63f4168d.png\"\/><br \/>  \u0414\u0430\u043b\u044c\u0448\u0435 \u0432\u043e \u0432\u043a\u043b\u0430\u0434\u043a\u0435 Artifacts \u0442\u043e\u0436\u0435 \u0443\u0434\u0430\u043b\u044f\u0435\u0442\u0435 \u0432\u0441\u0435 \u0430\u0440\u0442\u0435\u0444\u0430\u043a\u0442\u044b \u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442\u0435 \u043d\u043e\u0432\u044b\u0439 +,Web Application:Exploded,From modules,OK<br \/>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/web\/a3a\/1cc\/f18\/a3a1ccf184ab43a497096707fef8800a.png\"\/><br \/>  \u0414\u0430\u043b\u044c\u0448\u0435 \u0440\u0430\u0437\u0432\u0435\u0440\u0442\u044b\u0432\u0430\u0435\u043c Hibernate \u0438 \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0431\u044b\u043b\u043e \u0443\u0434\u043e\u0431\u043d\u043e, \u0437\u0430\u0441\u0443\u043d\u044c\u0442\u0435 \u044d\u0442\u0443 \u043c\u043e\u0434\u0435\u043b\u044c \u0432 \u043f\u0430\u043f\u043a\u0443 model, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432 by, \u0443\u043a\u0430\u0437\u0430\u0432 \u0432 \u044d\u0442\u043e\u0442 \u043f\u0443\u0442\u044c \u043f\u0440\u0438 \u0440\u0430\u0437\u0432\u0435\u0440\u0442\u043a\u0435 Hibernate.<br \/>  \u0412 \u043f\u0430\u043f\u043a\u0435 by \u0441\u043e\u0437\u0434\u0430\u0439\u0442\u0435 \u043f\u0430\u043f\u043a\u0443 util, \u0430 \u0432 \u043d\u0435\u0439 \u043a\u043b\u0430\u0441\u0441 HibernateUtil:  <\/p>\n<pre><code class=\"java\">package by.util;  import org.hibernate.SessionFactory; import org.hibernate.cfg.Configuration;   public class HibernateUtil {     private static SessionFactory sessionFactory=buildSessionFactory();      private static SessionFactory buildSessionFactory() {         try{             return new Configuration().configure().buildSessionFactory();         }catch (Exception e){             throw new ExceptionInInitializerError(e);         }     }      public static SessionFactory getSessionFactory() {         return sessionFactory;     } }  <\/code><\/pre>\n<p>  \u0411\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f HibernateUtil \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0439 SessionFactory \u043f\u043e\u0434 \u043d\u0430\u0448 \u043f\u0440\u043e\u0435\u043a\u0442.<br \/>  \u0412 \u043f\u0430\u043f\u043a\u0435 by \u0441\u043e\u0437\u0434\u0430\u0451\u043c \u043f\u0430\u043f\u043a\u0443 DAO, \u0432 \u043d\u0435\u0439 \u043a\u043b\u0430\u0441\u0441 DAOImple (\u043c\u044b \u043d\u0435 \u0441\u043e\u0437\u0434\u0430\u0451\u043c \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 DAO, \u0442\u0430\u043a \u043a\u0430\u043a \u043f\u0440\u0438\u043c\u0435\u0440 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439):  <\/p>\n<pre><code class=\"java\">package by.DAO;  import by.model.HeroesEntity; import by.util.HibernateUtil; import org.hibernate.Query; import org.hibernate.Session;  import java.util.List; public class DAOImple {     public void saveHero(HeroesEntity heroesEntity){         Session session= HibernateUtil.getSessionFactory().openSession();         session.beginTransaction();         session.save(heroesEntity);         session.getTransaction().commit();         session.close();     }     public List&lt;HeroesEntity&gt; getAll(){         Session session=HibernateUtil.getSessionFactory().openSession();         session.beginTransaction();         List&lt;HeroesEntity&gt; list=session.createQuery(&quot;from HeroesEntity&quot;).list();         session.getTransaction().commit();         session.close();         return list;     }     public void update(HeroesEntity heroesEntity){         Session session=HibernateUtil.getSessionFactory().openSession();         session.beginTransaction();         session.update(heroesEntity);         session.getTransaction().commit();         session.close();     } public HeroesEntity getHeroById(int id){         Session session=HibernateUtil.getSessionFactory().openSession();         session.beginTransaction();         Query query= session.createQuery(&quot;from HeroesEntity where idhero=:id&quot;);         query.setInteger(&quot;id&quot;,id);         HeroesEntity heroesEntity= (HeroesEntity) query.uniqueResult();         session.getTransaction().commit();         session.close();         return heroesEntity; } public void deleteHeroes(int id){     Session session=HibernateUtil.getSessionFactory().openSession();     session.beginTransaction();     Query query=session.createQuery(&quot;from HeroesEntity where idhero=:id&quot;);     query.setInteger(&quot;id&quot;,id);     HeroesEntity heroesEntity= (HeroesEntity) query.uniqueResult();     session.delete(heroesEntity);     session.getTransaction().commit();     session.close(); } } <\/code><\/pre>\n<p>  \u041a\u043b\u0430\u0441\u0441 DAOImple \u043d\u0430\u043c \u043d\u0443\u0436\u0435\u043d \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u0442\u043e\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0435\u0439, \u0447\u0442\u043e \u0435\u0441\u0442\u044c \u0432 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445.<br \/>  \u0412 \u043f\u0430\u043f\u043a\u0435 by \u0441\u043e\u0437\u0434\u0430\u0451\u043c \u043f\u0430\u043f\u043a\u0443 servlets, \u0430 \u0432 \u043d\u0435\u0439 \u0441\u043e\u0437\u0434\u0430\u0451\u043c \u0441\u0435\u0440\u0432\u043b\u0435\u0442(\u043d\u0435 \u043a\u043b\u0430\u0441\u0441!) SaveServlet (\u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0438 \u0432 \u043a\u043e\u0434\u0435):<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/web\/608\/af1\/530\/608af15300d84642b5b826587f3be0d3.png\"\/>  <\/p>\n<pre><code class=\"java\">package by.servlets;  import by.DAO.DAOImple; import by.model.HeroesEntity;  import javax.servlet.RequestDispatcher; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException;  public class SaveServlet extends HttpServlet {     protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {         DAOImple daoImple=new DAOImple();         \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/         \/\/INDEX.JSP         \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/         if(request.getParameter(&quot;add&quot;)!=null){\/\/\u043f\u0440\u0438 \u043d\u0430\u0436\u0430\u0442\u0438\u0438 \u043d\u0430 \u043a\u043d\u043e\u043f\u043a\u0443 add             HeroesEntity heroesEntity=new HeroesEntity();\/\/\u0441\u043e\u0437\u0434\u0430\u0451\u043c \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u043a\u043b\u0430\u0441\u0441\u0430 \u043c\u043e\u0434\u0435\u043b\u0438 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445             heroesEntity.setIdhero(Integer.parseInt(request.getParameter(&quot;id&quot;)));\/\/\u0437\u0430\u0434\u0430\u0451\u043c \u0435\u043c\u0443 id \u0432\u0437\u044f\u0442\u044b\u0439 \u0438\u0437 \u043f\u043e\u043b\u044f c \u0438\u043c\u0435\u043d\u0435\u043c id             heroesEntity.setName(request.getParameter(&quot;name&quot;));\/\/\u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e \u0441 \u043f\u0440\u043e\u0448\u043b\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u043e\u0439             daoImple.saveHero(heroesEntity);\/\/\u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u0432 \u0431\u0430\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442             request.setAttribute(&quot;list&quot;,daoImple.getAll());\/\/\u0441\u043e\u0437\u0434\u0430\u0451\u043c \u0430\u0442\u0442\u0440\u0438\u0431\u0443\u0442 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u0437\u044f\u043b \u0432 \u0441\u0435\u0431\u044f \u0432\u0441\u0451 \u0447\u0442\u043e \u0435\u0441\u0442\u044c \u0432 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445             RequestDispatcher requestDispatcher=request.getRequestDispatcher(&quot;list.jsp&quot;);\/\/\u043f\u0435\u0440\u0435\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0435\u043c\u0441\u044f \u043d\u0430 list.jsp             requestDispatcher.forward(request,response);         }         if(request.getParameter(&quot;showAll&quot;)!=null){\/\/\u043f\u0440\u0438 \u043d\u0430\u0436\u0430\u0442\u0438\u0438 \u043d\u0430 \u043a\u043d\u043e\u043f\u043a\u0443 showALL             request.setAttribute(&quot;list&quot;,daoImple.getAll());\/\/\u0441\u043e\u0437\u0434\u0430\u0451\u043c \u0430\u0442\u0442\u0440\u0438\u0431\u0443\u0442 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u0437\u044f\u043b \u0432 \u0441\u0435\u0431\u044f \u0432\u0441\u0451 \u0447\u0442\u043e \u0435\u0441\u0442\u044c \u0432 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445             RequestDispatcher requestDispatcher=request.getRequestDispatcher(&quot;list.jsp&quot;);\/\/\u043f\u0435\u0440\u0435\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0435\u043c\u0441\u044f \u043d\u0430 list.jsp             requestDispatcher.forward(request,response);         }         \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/         \/\/LIST.JSP         \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/         String action=request.getParameter(&quot;action&quot;);\/\/\u0441\u043e\u0437\u0434\u0430\u0451\u043c action \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0440\u0435\u0430\u0433\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0430 \u0442\u0435 \u0438\u043b\u0438 \u0438\u043d\u044b\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f         if(action.equalsIgnoreCase(&quot;update&quot;)){\/\/\u0435\u0441\u043b\u0438 action \u043e\u0442\u0440\u0435\u0430\u0433\u0438\u0440\u043e\u0432\u0430\u043b \u043d\u0430 update           request.setAttribute(&quot;hero&quot;,daoImple.getHeroById(Integer.parseInt(request.getParameter(&quot;idhero&quot;))));\/\/\u0441\u043e\u0437\u0434\u0430\u0451\u043c \u0430\u0442\u0440\u0438\u0431\u0443\u0442 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e id \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e\u0433\u043e HeroesEntity             RequestDispatcher requestDispatcher=request.getRequestDispatcher(&quot;update.jsp&quot;);\/\/\/\/\u043f\u0435\u0440\u0435\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0435\u043c\u0441\u044f \u043d\u0430 update.jsp             requestDispatcher.forward(request,response);         }         if(action.equalsIgnoreCase(&quot;delete&quot;)){\/\/\u0435\u0441\u043b\u0438 action \u043e\u0442\u0440\u0435\u0430\u0433\u0438\u0440\u043e\u0432\u0430\u043b \u043d\u0430 update             daoImple.deleteHeroes(Integer.parseInt(request.getParameter(&quot;idhero&quot;)));\/\/\u0443\u0434\u0430\u043b\u044f\u0435\u043c \u043f\u043e id             request.setAttribute(&quot;list&quot;,daoImple.getAll());\/\/\u0441\u043e\u0437\u0434\u0430\u0451\u043c \u0430\u0442\u0442\u0440\u0438\u0431\u0443\u0442 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u0437\u044f\u043b \u0432 \u0441\u0435\u0431\u044f \u0432\u0441\u0451 \u0447\u0442\u043e \u0435\u0441\u0442\u044c \u0432 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445             RequestDispatcher requestDispatcher=request.getRequestDispatcher(&quot;list.jsp&quot;);\/\/\u043f\u0435\u0440\u0435\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0435\u043c\u0441\u044f \u043d\u0430 list.jsp             requestDispatcher.forward(request,response);         }     }     protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {         DAOImple daoImple = new DAOImple(); \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/ \/\/ UPDATE.JSP \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/         if (request.getParameter(&quot;update&quot;) != null) {\/\/\u043f\u0440\u0438 \u043d\u0430\u0436\u0430\u0442\u0438\u0438 \u043d\u0430 \u043a\u043d\u043e\u043f\u043a\u0443 update             HeroesEntity heroesEntity = new HeroesEntity();\/\/\u0441\u043e\u0437\u0434\u0430\u0451\u043c \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u043a\u043b\u0430\u0441\u0441\u0430             heroesEntity.setIdhero(Integer.parseInt(request.getParameter(&quot;idhero&quot;)));\/\/\u0437\u0430\u0434\u0430\u0451\u043c id \u0438\u0437 \u043f\u043e\u043b\u044f idhero             heroesEntity.setName(request.getParameter(&quot;name&quot;));\/\/\u0437\u0430\u0434\u0430\u0451\u043c name \u0438\u0437 \u043f\u043e\u043b\u044f name             daoImple.update(heroesEntity);\/\/\u0430\u043f\u0434\u0435\u0439\u0442\u0438\u043c             request.setAttribute(&quot;list&quot;, daoImple.getAll());\/\/\u0441\u043e\u0437\u0434\u0430\u0451\u043c \u0430\u0442\u0442\u0440\u0438\u0431\u0443\u0442 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u0437\u044f\u043b \u0432 \u0441\u0435\u0431\u044f \u0432\u0441\u0451 \u0447\u0442\u043e \u0435\u0441\u0442\u044c \u0432 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445             RequestDispatcher requestDispatcher = request.getRequestDispatcher(&quot;list.jsp&quot;);\/\/\u043f\u0435\u0440\u0435\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0435\u043c\u0441\u044f \u043d\u0430 list.jsp             requestDispatcher.forward(request, response);         }     } }  <\/code><\/pre>\n<p>  \u0420\u0435\u0433\u0435\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u043c \u0441\u0435\u0440\u0432\u043b\u0435\u0442 \u0432 web.xml:  <\/p>\n<pre><code class=\"xml\">&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt; &lt;web-app xmlns=&quot;http:\/\/xmlns.jcp.org\/xml\/ns\/javaee&quot;          xmlns:xsi=&quot;http:\/\/www.w3.org\/2001\/XMLSchema-instance&quot;          xsi:schemaLocation=&quot;http:\/\/xmlns.jcp.org\/xml\/ns\/javaee http:\/\/xmlns.jcp.org\/xml\/ns\/javaee\/web-app_3_1.xsd&quot;          version=&quot;3.1&quot;&gt;     &lt;servlet&gt;         &lt;servlet-name&gt;SaveServlet&lt;\/servlet-name&gt;         &lt;servlet-class&gt;by.servlets.SaveServlet&lt;\/servlet-class&gt;     &lt;\/servlet&gt;     &lt;servlet-mapping&gt;         &lt;servlet-name&gt;SaveServlet&lt;\/servlet-name&gt;         &lt;url-pattern&gt;\/save&lt;\/url-pattern&gt;     &lt;\/servlet-mapping&gt; &lt;\/web-app&gt; <\/code><\/pre>\n<p>  \u0412 \u043f\u0430\u043f\u043a\u0435 web \u0441\u043e\u0437\u0434\u0430\u0451\u043c index.jsp \u0441\u0442\u0430\u0440\u0442\u043e\u0432\u0443\u044e \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443:  <\/p>\n<pre><code class=\"html\">&lt;%--   Created by IntelliJ IDEA.   User: \u0423\u0412\u0414   Date: 29.05.2017   Time: 18:18   To change this template use File | Settings | File Templates. --%&gt; &lt;%@ page contentType=&quot;text\/html;charset=UTF-8&quot; language=&quot;java&quot; %&gt; &lt;html&gt; &lt;head&gt;     &lt;title&gt;Title&lt;\/title&gt; &lt;\/head&gt; &lt;body&gt; &lt;form method=&quot;get&quot; action=&quot;\/save&quot;&gt;     &lt;input type=&quot;text&quot; name=&quot;id&quot;&gt;     &lt;input type=&quot;text&quot; name=&quot;name&quot;&gt;     &lt;input type=&quot;submit&quot; name=&quot;add&quot; value=&quot;add&quot;&gt;     &lt;input type=&quot;submit&quot; name=&quot;showAll&quot; value=&quot;showAll&quot;&gt; &lt;\/form&gt; &lt;\/body&gt; &lt;\/html&gt; <\/code><\/pre>\n<p>  \u0430 \u0442\u0430\u043a \u0436\u0435 list.jsp:  <\/p>\n<pre><code class=\"html\">&lt;%@ taglib prefix=&quot;c&quot; uri=&quot;http:\/\/java.sun.com\/jsp\/jstl\/core&quot; %&gt; &lt;%@ page contentType=&quot;text\/html;charset=UTF-8&quot; language=&quot;java&quot; %&gt; &lt;html&gt; &lt;head&gt;     &lt;title&gt;Title&lt;\/title&gt; &lt;\/head&gt; &lt;body&gt; &lt;table&gt;     &lt;tr&gt;         &lt;td&gt;id&lt;\/td&gt;         &lt;td&gt;name&lt;\/td&gt;     &lt;\/tr&gt;     &lt;c:forEach items=&quot;${list}&quot; var=&quot;list&quot;&gt;         &lt;tr&gt;             &lt;th&gt;${list.idhero}&lt;\/th&gt;             &lt;th&gt;${list.name}&lt;\/th&gt;             &lt;th&gt;&lt;a href=&quot;\/save?action=update&idhero=&lt;c:out value=&quot;${list.idhero}&quot;\/&gt;&quot;&gt;update&lt;\/a&gt; &lt;\/th&gt;             &lt;th&gt;&lt;a href=&quot;\/save?action=delete&idhero=${list.idhero}&quot;&gt;delete&lt;\/a&gt; &lt;\/th&gt;         &lt;\/tr&gt;     &lt;\/c:forEach&gt; &lt;\/table&gt; &lt;\/body&gt; &lt;\/html&gt; <\/code><\/pre>\n<p>  \u0438 update.jsp:  <\/p>\n<pre><code class=\"html\">&lt;%@ taglib prefix=&quot;c&quot; uri=&quot;http:\/\/java.sun.com\/jsp\/jstl\/core&quot; %&gt; &lt;%@ page contentType=&quot;text\/html;charset=UTF-8&quot; language=&quot;java&quot; %&gt; &lt;html&gt; &lt;head&gt;     &lt;title&gt;Title&lt;\/title&gt; &lt;\/head&gt; &lt;body&gt; &lt;form method=&quot;post&quot; action=&quot;\/save&quot;&gt;         &lt;input type=&quot;text&quot; name=&quot;idhero&quot; readonly=&quot;readonly&quot; value=&quot;&lt;c:out value=&quot;${hero.idhero}&quot;\/&gt;&quot;&gt;         &lt;input type=&quot;text&quot; name=&quot;name&quot; value=&quot;&lt;c:out value=&quot;${hero.name}&quot;\/&gt;&quot;&gt;     &lt;input type=&quot;submit&quot; value=&quot;ok&quot; name=&quot;update&quot;&gt; &lt;\/form&gt; &lt;\/body&gt; &lt;\/html&gt; <\/code><\/pre>\n<p>  \u0414\u0430\u043b\u044c\u0448\u0435 \u043d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0435\u043c TomCat:<br \/>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/web\/407\/675\/fa6\/407675fa66c1488b9c763d7f938c6dbc.png\"\/><br \/>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/web\/3cc\/16e\/bde\/3cc16ebdeef04730b8a06203b1925e8b.png\"\/><br \/>  \u0414\u0430\u0451\u043c \u0435\u043c\u0443 \u0430\u0440\u0442\u0435\u0444\u0430\u043a\u0442(\u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u043d\u0430\u0436\u0430\u0442\u044c \u0432\u043d\u0438\u0437\u0443 \u043d\u0430 \u043a\u043d\u043e\u043f\u043a\u0443 \u0441 \u043a\u0440\u0430\u0441\u043d\u043e\u0439 \u043b\u0430\u043c\u043f\u043e\u0447\u043a\u043e\u0439 \u0438 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435\u043c Fix):<br \/>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/web\/f54\/019\/c33\/f54019c335914373bc8301a7fae460fa.png\"\/><br \/>  \u042f \u043d\u0430\u0434\u0435\u044e\u0441\u044c \u0447\u0442\u043e \u0432\u0430\u043c \u0443\u0434\u0430\u043b\u043e\u0441\u044c \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u044d\u0442\u043e\u0442 \u043f\u0440\u0438\u043c\u0435\u0440 \u0435\u0441\u043b\u0438 \u0436\u0435 \u043d\u0435\u0442 \u043c\u043e\u0436\u0435\u0442\u0435 \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u0441\u044f \u043a\u043e \u043c\u043d\u0435 \u0432 vk:<a href=\"https:\/\/vk.com\/romeolord\">\u0441\u0441\u044b\u043b\u043a\u0430<\/a><br \/>  \u042d\u0442\u043e\u0442 \u043f\u0440\u0438\u043c\u0435\u0440 \u043d\u0430 github:<a href=\"https:\/\/github.com\/Dardem30\/Hibernate-JSP\">\u0437\u0434\u0435\u0441\u044c<\/a><br \/>  \u0423\u0434\u0430\u0447\u0438!<br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habrahabr.ru\/post\/329924\/\"> https:\/\/habrahabr.ru\/post\/329924\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u0412\u0441\u0435\u043c \u043f\u0440\u0438\u0432\u0435\u0442!<br \/>  \u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443 \u043e \u0442\u043e\u043c, \u043a\u0430\u043a \u0441\u0432\u044f\u0437\u0430\u0442\u044c JSP \u0441 Hibernate \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u0441\u0435\u0440\u0432\u043b\u0435\u0442\u0430. \u042f \u043d\u0430\u0434\u0435\u044e\u0441\u044c, \u0447\u0442\u043e \u0432\u044b \u0443\u043c\u0435\u0435\u0442\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 Hibernate, \u0435\u0441\u043b\u0438 \u0436\u0435 \u043d\u0435\u0442, \u0442\u043e \u043d\u0430\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u044e \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u044d\u0442\u0443 <a href=\"https:\/\/habrahabr.ru\/post\/320542\/\">\u0441\u0442\u0430\u0442\u044c\u044e<\/a>. \u0422\u0430\u043a\u0436\u0435 \u044f \u043d\u0430\u0434\u0435\u044e\u0441\u044c, \u0447\u0442\u043e \u0432\u044b \u0437\u043d\u0430\u043a\u043e\u043c\u044b \u0441 \u0441\u0435\u0440\u0432\u043b\u0435\u0442\u0430\u043c\u0438 \u0438 \u0445\u043e\u0442\u044c \u0440\u0430\u0437 \u0438\u0445 \u0443\u0441\u043f\u0435\u0448\u043d\u043e \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u043b\u0438. <br \/>  \u0414\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0443 \u0432\u0430\u0441 \u0431\u044b\u043b\u0430 \u0442\u0430\u043a\u0430\u044f \u0436\u0435 \u0431\u0430\u0437\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 MySQL, \u0432\u0441\u0442\u0430\u0432\u044c\u0442\u0435 \u0442\u0443\u0434\u0430 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043a\u043e\u0434:<br \/>  CREATE SCHEMA `hero`;<\/p>\n<p>  CREATE TABLE `hero`.`heroes`<br \/>  (<br \/>  `idhero` INT NOT NULL AUTO_INCREMENT,<br \/>  `name` VARCHAR(45) NOT NULL,<br \/>  PRIMARY KEY (`idhero`));<br \/>  \u0421\u043e\u0437\u0434\u0430\u0451\u043c maven \u043f\u0440\u043e\u0435\u043a\u0442 \u0438 \u0432\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u0438 \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e:  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-287153","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/287153","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=287153"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/287153\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=287153"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=287153"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=287153"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}