Vous êtes sur la page 1sur 2

http://tollfreesms.bksms.

in/
<%@page import="java.sql.*,java.io.*"%>
<%
try{
InputStream sImage;
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:
3306/test", "root", "root");
File imgfile = new File("C:/flower3.jpg");
FileInputStream fin = new FileInputStream(imgfile);
PreparedStatement pre = con.prepareStatement("insert into image(images) va
lues(?)");
pre.setBinaryStream(1,fin,(int)imgfile.length());
pre.executeUpdate();
System.out.println("Inserting Successfully!");
pre.close();
Statement st=con.createStatement();
ResultSet rs=st.executeQuery("select images from image where id=1");
if(rs.next()){
byte[] bytearray = new byte[1048576];
int size=0;
sImage = rs.getBinaryStream(1);
response.reset();
response.setContentType("image/jpeg");
while((size=sImage.read(bytearray))!= -1 ){
response.getOutputStream().write(bytearray,0,size);
}
}
rs.close();
st.close();
con.close();
}
catch(Exception ex){
out.println("error :"+ex);
}
%>
Example
Here, a template JSP defines the layout. It includes a header, footer, and navig
ation links. A <jsp:include> inserts the main content or "body" of the page. The
re are two parameters to the template, which are passed in as request parameters
: ?TTitle, used in the <title> tag
?TBody, which is simply the name of the JSP which supplies all page content not
otherwise defined in the template.
The <tags:xxx/> items refer to .tag files, that contain small JSP snippets. <%@
include file="/JspHeader.jsp" %>
<
!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd"
>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=uTF-8">
<%-- TTitle is a request parameter for the templated page title. --%>
<title>
Fish and Chips Club - ${param.TTitle} </title>
<link rel="stylesheet" type="text/css" href="../../stylesheet.css" media="all">
</head>
<body>
<div align="center">
<img class="no-margin" src="../../images/logo.jpg" alt="Fish And Chips Club">
</div>
<div class="header">
"The Total Fish & Chips Dining Experience"
</div>
<div class="menu-bar">
<w:highlightCurrentPage styleClass='highlight'>
<c:url value="/main/home/HomePageAction.do" var="homeURL"/>
<A href='${homeURL}'>Home</a>
<c:url value="/main/rsvp/RsvpShow.do" var="showRsvpURL"/>
<A href='${showRsvpURL}'>Rsvp</a>
<c:url value="/all/logoff/LogoffAction.do" var="logoffURL"/>
<A href='${logoffURL}'>Log Off</a>
</w:highlightCurrentPage>
</div>
<%-- Display error and information messages. --%>
<tags:displayMessages/>
<%-- TBody is a request parameter for the templated page body. --%>
<div class="body">
<c:if test="${not empty param.TBody}">
<jsp:include page='${param.TBody}' flush="true"/>
</c:if>
<c:if test="${empty param.TBody}">
<jsp:include page="Error.jsp" flush="true"/>
</c:if>
</div>
<tags:footer/>
</body>
</html>

Vous aimerez peut-être aussi