Create a java file for the decoding the image
Image.java
package com.img.action;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import javax.imageio.ImageIO;
import javax.servlet.ServletRequest;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts2.ServletActionContext;
import com.img.dao.ConnectionDAO;
import com.img.pojo.Film_TablePojo;
import com.img.pojo.imagePojo;
import com.opensymphony.xwork2.ActionSupport;
public class Show extends ActionSupport {
List<Object> values = new ArrayList<Object>();
public List<Object> getValues() {
return values;
}
public void setValues(List<Object> values) {
this.values = values;
}
/*HttpServletRequest request;
public void setServletRequest(HttpServletRequest request) {
this.request = request;
}
public HttpServletRequest getServletRequest() {
return request;
} */
@Override
public String execute() throws Exception {
ConnectionDAO con = new ConnectionDAO();
values=con.nowshowing();
System.out.println(values);
return "success";
}
}
2)ConnectionDao.java
package com.img.dao;
import java.util.ArrayList;
import java.util.List;
import org.hibernate.Criteria;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.SQLQuery;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
import com.img.pojo.Film_TablePojo;
import com.img.pojo.imagePojo;
public class ConnectionDAO {
Configuration con = new Configuration().configure("hibernate.cfg.xml");
SessionFactory sf = con.buildSessionFactory();
Session session;
@SuppressWarnings("unchecked")
public List<Object> nowshowing() {
List<Object> lista1 = new ArrayList<Object>();
Session session = sf.openSession();
try {
Query qry = session.createQuery("FROM Film_TablePojo f");
lista1 = qry.list();
} catch (Exception e) {
e.printStackTrace();
}
return lista1;
}
}
3)Image Pojo table.
film_tablepojo.java
package com.img.pojo;
import java.util.Set;
public class Film_TablePojo {
imagePojo p;
public imagePojo getP() {
return p;
}
public void setP(imagePojo p) {
this.p = p;
}
private int flim_id;
private int cinema_id;
private String title;
private String description;
private String running_time;
private String director;
private String musicdirector;
private String artist;
private int image_id;
private int rating;
private byte[] image;
private String release_date;
public String getRelease_date() {
return release_date;
}
public void setRelease_date(String release_date) {
this.release_date = release_date;
}
public byte[] getImage() {
return image;
}
public void setImage(byte[] image) {
this.image = image;
}
public int getRating() {
return rating;
}
public void setRating(int rating) {
this.rating = rating;
}
public int getFlim_id() {
return flim_id;
}
public void setFlim_id(int flim_id) {
this.flim_id = flim_id;
}
public int getCinema_id() {
return cinema_id;
}
public void setCinema_id(int cinema_id) {
this.cinema_id = cinema_id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getRunning_time() {
return running_time;
}
public void setRunning_time(String running_time) {
this.running_time = running_time;
}
public String getDirector() {
return director;
}
public void setDirector(String director) {
this.director = director;
}
public String getMusicdirector() {
return musicdirector;
}
public void setMusicdirector(String musicdirector) {
this.musicdirector = musicdirector;
}
public String getArtist() {
return artist;
}
public void setArtist(String artist) {
this.artist = artist;
}
public int getImage_id() {
return image_id;
}
public void setImage_id(int image_id) {
this.image_id = image_id;
}
}
(**)Create for this hbm file
(**)cretate a image file for pojo class
imagepojo.java:
package com.img.pojo;
import java.util.Date;
import java.util.Set;
import com.mysql.jdbc.Blob;
import com.sun.mail.iap.ByteArray;
public class imagePojo {
private int image_id;
private String imgName;
private String picImage;
public int getImage_id() {
return image_id;
}
public void setImage_id(int image_id) {
this.image_id = image_id;
}
public String getImgName() {
return imgName;
}
public void setImgName(String imgName) {
this.imgName = imgName;
}
public String getPicImage() {
return picImage;
}
public void setPicImage(String picImage) {
this.picImage = picImage;
}
}
(11)Create a hbm file for the image pojo class
(11)Hibernate cfg.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!-- <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration> -->
<!DOCTYPE hibernate-configuration SYSTEM
"classpath://org/hibernate/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/ticketbooking</property>
<property name="hibernate.connection.username">root</property>
<property name="connection.password">root</property>
<property name="connection.pool_size">1</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="show_sql">true</property>
<property name="hbm2ddl.auto">update</property>
<mapping resource="com/img/pojo/imagePojo.hbm.xml" />
<mapping resource="com/img/pojo/Film_TablePojo.hbm.xml" />
<!-- <mapping class="com.kclink.krp.pojo.imagePojo"/> -->
</session-factory>
</hibernate-configuration>
II)struts.xml:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.1//EN"
"/WEB-INF/dtds/struts-2.1.dtd">
<struts>
<constant name="struts.ognl.allowStaticMethodAccess" value="true"/>
<package name="default" extends="struts-default">
<action name="get" class="com.img.action.Show" method="execute">
<result name="success">index.jsp</result>
</action>
</package>
</struts>
II)web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
<display-name>image</display-name>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>NewFile.jsp</welcome-file>
</welcome-file-list>
</web-app>
Comments
Post a Comment