Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <%@page import="javax.servlet.annotation.MultipartConfig"%>
- <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
- pageEncoding="ISO-8859-1" import="java.sql.*"%>
- <!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=ISO-8859-1">
- <title>Insert title here</title>
- </head>
- <body>
- <%
- try{
- Class.forName("com.mysql.jdbc.Driver");
- Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/demo","apoorv","june1998");
- Statement sta = con.createStatement();
- ResultSet rs = sta.executeQuery("select * from mehul;");
- while(rs.next()){
- String s = rs.getString("name");
- %><p><%=s %></p>
- <img src="<%=rs.getString("image")%>>
- <%
- x }
- }
- catch(Exception e){
- } %>
- </body>
- </html>
- <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
- pageEncoding="ISO-8859-1"%>
- <!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=ISO-8859-1">
- <title>Insert title here</title>
- </head>
- <body>
- <form method="post" action="ImageProc" enctype="multiport/form-data">
- <input type="text" name="name"/>
- <input type="file" name="image" />
- <input type="submit" value="Submit">
- </form>
- </body>
- </html>
- package controller;
- import java.io.FileInputStream;
- import java.io.IOException;
- import java.io.InputStream;
- import java.sql.DriverManager;
- import javax.servlet.ServletContext;
- import javax.servlet.ServletException;
- import javax.servlet.annotation.MultipartConfig;
- import javax.servlet.annotation.WebServlet;
- import javax.servlet.http.HttpServlet;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import javax.servlet.http.Part;
- import java.sql.*;
- @MultipartConfig
- @WebServlet("/ImageProc")
- public class ImageProc extends HttpServlet {
- private static final long serialVersionUID = 1L;
- @Override
- protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
- ServletContext ctx = getServletContext();
- System.out.println(ctx.getMajorVersion());
- System.out.println(ctx.getMinorVersion());
- }
- protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
- String name = request.getParameter("name");
- String img = request.getParameter("image");
- FileInputStream file = new FileInputStream(img);
- System.out.print(img);
- // Part img = request.getPart("image");
- // InputStream stream = img.getInputStream();
- try{
- Class.forName("com.mysql.jdbc.Driver");
- Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/demo","apoorv","june1998");
- PreparedStatement ps = con.prepareStatement("insert into mehul values(?,?) ;");
- ps.setString(1,name);
- ps.setBinaryStream(2,file,file.available());
- ps.execute();
- System.out.println("Mehu rocxxx");
- }
- catch(Exception e){
- }
- }
- public static void main(String[] args) {
- }
- }
Add Comment
Please, Sign In to add comment