package com.li.servlet;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.nio.ByteBuffer;
import java.sql.*;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.Part;
import javax.swing.JOptionPane;
import com.li.utils.*;
public class register extends HttpServlet {
/**
* Constructor of the object.
*/
public register() {
super();
}
/**
* Destruction of the servlet. <br>
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}
/**
* The doGet method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
out.println("<HTML>");
out.println(" <HEAD><TITLE>A Servlet</TITLE></HEAD>");
out.println(" <BODY>");
out.print(" This is ");
out.print(this.getClass());
out.println(", using the GET method");
out.println(" </BODY>");
out.println("</HTML>");
out.flush();
out.close();
}
/**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to post.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=GBK");
PrintWriter out=response.getWriter();
request.setCharacterEncoding("GBK");
String username=request.getParameter("username");
String password=request.getParameter("password");
String realname=request.getParameter("realname");
String number=request.getParameter("number");
String qq=request.getParameter("qq");
String phone=request.getParameter("phone");
String identity=request.getParameter("identity");
String work=request.getParameter("work");
String prize=request.getParameter("prize");
Part part = request.getPart("imageContent");
String filename=request.getParameter("image");
System.out.println(filename);
File file = new File("C:\\Users\\高振\\Pictures\\Saved Pictures\\"+filename); //获取表单传过来的图片的url
System.out.println(file);
System.out.println(username);
System.out.println(identity);
try {
String sql1 = "insert into user(username,password,realname,number,qq,phone,identity,work,prize) values('"+username+"','"+password+"','"+realname+"','"+number+"','"+qq+"','"+phone+"','"+identity+"','"+work+"','"+prize+"')";
JDBCutil.insert(sql1);
out.print("<script language='javascript'>alert('注册成功!');window.location.href='login.jsp';</script>");
System.out.println("注册成功!");
out.flush();
JDBCutil.stop();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
//打开文件
FileInputStream fin = new FileInputStream(file);
//建一个缓冲保存数据
ByteBuffer nbf = ByteBuffer.allocate((int) file.length());
byte[] array = new byte[1024];
int offset = 0, length = 0;
//读存数据
while ((length = fin.read(array)) > 0) {
if (length != 1024)
nbf.put(array, 0, length);
else
nbf.put(array);
offset += length;
}
//新建一个数组保存要写的内容
byte[] content = nbf.array();
//创建数据库连接
Connection conn= com.li.utils.JDBCutil.getconnection();
//保存数据
Statement stmt =conn.createStatement(
ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_UPDATABLE);
String sqlstr = "select * from user where username='"+username+"'";
ResultSet rs = stmt.executeQuery(sqlstr);
if (rs.next())
{
rs.updateBytes(12, content);
rs.updateRow();
} else {
rs.moveToInsertRow();
rs.updateBytes(12, content);
rs.insertRow();
}
rs.close();
// 关闭文件
fin.close();
System.out.println("恭喜,已经将新的记录成功地添加到数据库中!");
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (SQLException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
}
/* private String getFileNameFromPart(Part part) {
String header = part.getHeader("Content-Disposition");
return header.substring(header.indexOf("filename=\"") + 10, header.lastIndexOf("\""));
}*/
/**
* Initialization of the servlet. <br>
*
* @throws ServletException if an error occurs
*/
public void init() throws ServletException {
// Put your code here
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
web技术实现个人主页管理系统 (108个子文件)
register.class 5KB
sign.class 5KB
update.class 5KB
login.class 4KB
CheckServlet.class 4KB
HttpUtil.class 3KB
SendSMS.class 3KB
download.class 3KB
del.class 2KB
JDBCutil.class 2KB
loginout.class 2KB
Userbean.class 2KB
adloginout.class 1KB
IndustrySMS.class 1KB
RandomNum.class 677B
Config.class 549B
Config.class 535B
client.class 391B
.classpath 1KB
org.eclipse.wst.common.component 462B
org.eclipse.wst.jsdt.ui.superType.container 49B
main.css 6KB
index.css 3KB
base.css 3KB
mysql-connector-java-5.1.44-bin.jar 976KB
commons-fileupload-1.2.1-javadoc.jar 269KB
commons-codec-1.9.jar 258KB
gson-2.0.jar 198KB
commons-fileupload-1.2.1-sources.jar 72KB
commons-fileupload-1.2.1.jar 56KB
register.java 5KB
sign.java 5KB
update.java 5KB
login.java 4KB
CheckServlet.java 3KB
HttpUtil.java 3KB
download.java 3KB
loginout.java 3KB
del.java 2KB
SendSMS.java 2KB
adloginout.java 2KB
JDBCutil.java 1KB
Userbean.java 975B
IndustrySMS.java 782B
Config.java 549B
Config.java 494B
RandomNum.java 198B
client.java 106B
footside.jpg 233KB
headbg.jpg 39KB
03.jpg 32KB
navbg.jpg 29KB
yuanshan.jpg 25KB
02.jpg 21KB
01.jpg 19KB
logo.jpg 18KB
bg.jpg 16KB
06.jpg 16KB
04.jpg 15KB
img_2.jpg 13KB
img_1.jpg 11KB
topbg.jpg 10KB
img_3.jpg 9KB
img_4.jpg 8KB
gz01.jpg 4KB
gz03.jpg 4KB
gz04.jpg 4KB
mainendbg.jpg 3KB
maintopbg.jpg 3KB
gz02.jpg 3KB
time.jpg 1KB
libg.jpg 543B
jquery-1.8.3.min.js 96KB
jquery.js 30KB
modernizr.js 28KB
.jsdtscope 500B
welcome.jsp 11KB
newslistpic.jsp 6KB
about.jsp 6KB
study.jsp 6KB
sign.jsp 6KB
lastweeksign.jsp 6KB
update.jsp 5KB
listpic.jsp 4KB
register.jsp 3KB
user.jsp 2KB
smslogin.jsp 2KB
manage.jsp 2KB
login.jsp 1KB
query.jsp 1KB
Show.jsp 1KB
MANIFEST.MF 36B
豆花之歌.mp3 3.41MB
.mymetadata 297B
org.eclipse.wst.jsdt.ui.superType.name 6B
navbg.png 65KB
rtitbg.png 20KB
gz04.png 5KB
gz01.png 4KB
gz02.png 4KB
共 108 条
- 1
- 2
资源评论
qq_42262292
- 粉丝: 1
- 资源: 4
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功