web个人游戏信息管理网站
立即下载
资源介绍:
适合初学者,用来下载学习,能够帮助初学者快速上手的web前端代码项目。里面用到的东西有JavaScript和JavaBean以及数据库,css风格自定义。web除了框架最基础的也就是这些东西了,学好这些东西,根据项目学习web基础,然后就可以继续深入发展了
package bean;
import java.io.File;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
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;
/**
* Servlet implementation class gamechange
*/
@WebServlet("/gamechange")
@MultipartConfig
public class gamechange extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public gamechange() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doPost(request,response);
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
request.setCharacterEncoding("UTF-8");
response.setContentType("text/html;charset=utf-8");
try {
Class.forName("com.mysql.jdbc.Driver" );
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
Connection conn = null;
Statement statement = null;
String url = "jdbc:mysql://localhost:3306/mysql_db";
String user = "root";
String password = "123456";
try {
conn = DriverManager.getConnection (url,user,password );
statement = conn.createStatement();
String gamen=request.getParameter("gamen");
String stime=request.getParameter("stime");
String bq=request.getParameter("bq");
String price=request.getParameter("price");
if(!stime.equals("")&&stime!=null){
statement.executeUpdate("update gameinfo set stime='"+stime+"' where gamen='"+gamen+"'");
}
if(!bq.equals("")&&bq!=null){
statement.executeUpdate("update gameinfo set bq='"+bq+"' where gamen='"+gamen+"'");
}
if(!price.equals("")&&price!=null){
statement.executeUpdate("update gameinfo set price='"+price+"' where gamen='"+gamen+"'");
}
Part part=request.getPart("file");
long filesize = part.getSize();
if(filesize!=0){
String filename=part.getSubmittedFileName();
String filepath=request.getServletContext().getRealPath("gameprit/");
filename=new File(filename).getName();
part.write(filepath+"/"+filename);
statement.executeUpdate("update gameinfo set text='"+filename+"' where gamen='"+gamen+"'");
}
ResultSet rs=statement.executeQuery("select * from gameinfo");
List gamelist = new ArrayList<>();
while(rs.next()){
gameinfo a=new gameinfo(rs.getString("gamen"),rs.getString("stime"),rs.getString("bq"),rs.getString("price"),rs.getString("text"));
gamelist.add(a);
}
request.setAttribute("gameinfo", gamelist);
request.getRequestDispatcher("main.jsp").forward(request, response);
rs.close();
statement.close();
conn.close();
}catch(Exception e){e.printStackTrace();}
}
}