package tom.jiafei;
import java.io.*;
import tom.jiafei.xinxi;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.sql.*;
public class Safe extends HttpServlet {
/**
* Constructor of the object.
*/
public Safe() {
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 {
File a=new File("D:/ceshi/2/2.txt");
FileOutputStream a1=new FileOutputStream(a);
InputStream b1=request.getInputStream();
byte v[]=new byte[20000];
int n;
while((n=b1.read(v))!=-1)
a1.write(v, 0, n);
a1.close();
b1.close();
String filename="t.txt";
byte cc[]=filename.getBytes("ISO-8859-1");
filename=new String(cc);
File c1=new File("D:/ceshi/2/"+filename);
RandomAccessFile randomwrite=new RandomAccessFile(c1,"rw");
RandomAccessFile randomread=new RandomAccessFile(a,"r");
int second=1;
String secondLine=null;
while(second<=2)
{
secondLine=randomread.readLine();
second++;
}
randomread.seek(0);
long four=0;
int four1=1;
while((n=randomread.readByte())!=-1&&(four1<=4))
{
if(n=='\n')
{
four=randomread.getFilePointer();
four1++;
}
}
randomread.seek(randomread.length());
long end=randomread.getFilePointer();
int j=1;
while( (end>=0) && (j<6))
{
end--;
randomread.seek(end);
n=randomread.readByte();
if(n=='\n')
{
end=randomread.getFilePointer();
j++;
}
randomread.seek(four);
while(four<end-1)
{
n=randomread.readByte();
randomwrite.write(n);
four=randomread.getFilePointer();
}
randomread.close();
randomwrite.close();
}
/* try {
Class.forName("com.mysql.jdbc.Driver");
} catch (Exception e) {
// TODO: handle exception
}
Connection con;
Statement sql = null;
ResultSet rs = null;
String uri="jdbc:mysql://localhost:3306/qwer?user=root&password=root&characterEncoding=gb2312";
try {
con=DriverManager.getConnection(uri);
sql=con.createStatement();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
xinxi xinxi=new xinxi();
HttpSession session=request.getSession();
session.setAttribute("xinxi",xinxi);
String yonghuming=request.getParameter("yonghuming");
String mima=request.getParameter("mima");
String cha="";
int l=1;
String l1=request.getParameter("jieshou");
l=Integer.parseInt(l1);
String name="";
switch(l)
{
case 10:
{
name="xuesheng";
cha="insert into xuesheng values(3,'xc','xv')";
try {
sql.executeUpdate(cha);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
case 11:
{
name="xuesheng";
cha="update xuesheng set 姓名='123',学号='qwe'";
try {
sql.executeUpdate(cha);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
case 2:
{
}
case 3:
{
}
}
xinxi.setYonghuming(yonghuming);
xinxi.setMima(mima);
String ty="select * from jiaoshi";
try {
rs= sql.executeQuery(ty);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
RequestDispatcher dispatcher=request.getRequestDispatcher("ceshi.jsp");
dispatcher.forward(request, response);
PrintWriter out=response.getWriter();*/
/*try {
rs.next();
for(int i = 0;i<=rs.getRow();i++)
out.println(rs.getString(i+1));
sql.executeUpdate(cha);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}*/
}
/**
* Initialization of the servlet. <br>
*
* @throws ServletException if an error occurs
*/
public void init() throws ServletException {
// Put your code here
}
}