首页 新闻 会员 周边 捐助

求大神注释!

-1
悬赏园豆:5 [待解决问题]

package org.fjzzy.webservlets;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.LinkedList;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.fjzzy.mysql_action.ConDB;

/**
 * Servlet implementation class AddCommentServlet
 */
@WebServlet("/AddComment")
public class AddCommentServlet extends HttpServlet {
 private static final long serialVersionUID = 1L;
      
    /**
     * @see HttpServlet#HttpServlet()
     */
    public AddCommentServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

 /**
  * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
  */
 protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  request.setCharacterEncoding("UTF-8");
  response.setCharacterEncoding("UTF-8");
  ConDB conDB=new ConDB();
  String content=request.getParameter("content");
  String userName=request.getParameter("userName");
  String classId=request.getParameter("classId");
  String sql="INSERT INTO comment (classId,userName,content) VALUES(?,?,?)";
  LinkedList<String> ls=new LinkedList<>();
  ls.addLast(classId);
  ls.addLast(userName);
  ls.addLast(content);
  conDB.QueryAction(sql, ls);
  String sqlSelect="SELECT * FROM user WHERE userName=? or Name=?";
  ResultSet rSet=conDB.QuerySelect(sqlSelect,userName,userName);
  try {
   if(rSet.next()){
    response.setContentType("text/xml;charset=UTF-8");
    PrintWriter writer=response.getWriter();
    writer.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
    writer.write("<list>");
    writer.write("<comment>");
    writer.write("<userName content='"+content+"' imgUrl='"+rSet.getString("imgUrl")+"'>"+userName+"</userName>");
    writer.write("</comment>");
    writer.write("</list>");
   }else{
    response.getWriter().print(0);
   }
  } catch (SQLException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }finally{
   conDB.close();
  }
 }

 /**
  * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
  */
 protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  // TODO Auto-generated method stub
  doGet(request, response);
 }

}



package org.fjzzy.webservlets;

import java.io.IOException;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.fjzzy.mysql_action.ConDB;

/**
 * Servlet implementation class ChangePassWordServlet
 */
@WebServlet("/ChangePassWord")
public class ChangePassWordServlet extends HttpServlet {
 private static final long serialVersionUID = 1L;
      
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ChangePassWordServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

 /**
  * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
  */
 protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  request.setCharacterEncoding("UTF-8");
  response.setCharacterEncoding("UTF-8");
  ConDB conDB=new ConDB();
  String newPsd=request.getParameter("newpsd");
  String oldPsd=request.getParameter("oldpsd");
  String userName=request.getParameter("userName");
  String sql="SELECT * FROM user WHERE passWord=? and userName=?";
  try {
   if(conDB.QuerySelect(sql, oldPsd, userName).next()){
    String sqlAction="UPDATE user SET passWord=? WHERE userName=?";
    conDB.QueryAction(sqlAction, newPsd, userName);
    response.getWriter().print("1");
   }else{
    response.getWriter().print("0");
   }
  } catch (SQLException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }finally{
   conDB.close();
  }
 }

 /**
  * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
  */
 protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  // TODO Auto-generated method stub
  doGet(request, response);
 }

}

package org.fjzzy.webservlets;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.ResultSet;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.fjzzy.mysql_action.ConDB;


/**
 * Servlet implementation class ClassShowServlet
 */
@WebServlet("/ClassShow")
public class ClassShowServlet extends HttpServlet {
 private static final long serialVersionUID = 1L;
      
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ClassShowServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

 /**
  * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
  */
 protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  request.setCharacterEncoding("UTF-8");
  response.setCharacterEncoding("UTF-8");
  ConDB conDB=new ConDB();
  String imgUrl="";
  String userName=request.getParameter("userName");
  String classId=request.getParameter("classId");
  String sql="SELECT * FROM class WHERE classId=?";
  String sql1="SELECT * FROM user WHERE userName=?";
  String sql2="SELECT * FROM comment WHERE classId=?";
  String sqlDoc="SELECT * FROM doc WHERE classId=?";
  String sqlVideo="SELECT * FROM video WHERE classId=?";
  String sqlPpt="SELECT * FROM ppt WHERE classId=?";
  ResultSet rSet=conDB.QuerySelect(sql, classId);
  ResultSet rSet2=conDB.QuerySelect(sql1, userName);
  ResultSet rSet3=conDB.QuerySelect(sql2,classId);
  ResultSet rSetDoc=conDB.QuerySelect(sqlDoc, classId);
  ResultSet rSetPpt=conDB.QuerySelect(sqlPpt, classId);
  ResultSet rSetVideo=conDB.QuerySelect(sqlVideo, classId);
  response.setContentType("text/xml;charset=UTF-8");
  PrintWriter writer=response.getWriter();
  writer.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
  writer.write("<list>");
  try {
   while(rSet.next()){
    writer.write("<classInfo>"+rSet.getString("classInfo")+"</classInfo>");
    writer.write("<classImg>"+rSet.getString("classImg")+"</classImg>");
   }
   while(rSet2.next()){
    writer.write("<focus>"+rSet2.getString("focus")+"</focus>");
    imgUrl=rSet2.getString("imgUrl");
   }
   while(rSet3.next()){
    writer.write("<comment>");
    writer.write("<userName content='"+rSet3.getString("content")+"' imgUrl='"+imgUrl+"'>"+rSet3.getString("userName")+"</userName>");
    writer.write("</comment>");
   }
   while(rSetDoc.next()){
    writer.write("<doc>");
    writer.write("<docUrl>"+rSetDoc.getString("docUrl")+"</docUrl>");
    writer.write("<docName>"+rSetDoc.getString("docName")+"</docName>");
    writer.write("</doc>");
   }
   while(rSetPpt.next()){
    writer.write("<ppt>");
    writer.write("<pptUrl>"+rSetPpt.getString("pptUrl")+"</pptUrl>");
    writer.write("<pptName>"+rSetPpt.getString("pptName")+"</pptName>");
    writer.write("</ppt>");
   }
   while(rSetVideo.next()){
    writer.write("<video>");
    writer.write("<videoUrl>"+rSetVideo.getString("videoUrl")+"</videoUrl>");
    writer.write("<videoName>"+rSetVideo.getString("videoName")+"</videoName>");
    writer.write("</video>");
   }
   writer.write("</list>");
  } catch (SQLException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }finally{
   conDB.close();
  }
  
 }

 /**
  * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
  */
 protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  // TODO Auto-generated method stub
  doGet(request, response);
 }

}

package org.fjzzy.webservlets;

import java.io.IOException;
import java.util.LinkedList;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.fjzzy.mysql_action.ConDB;

/**
 * Servlet implementation class EditUserInfoServlet
 */
@WebServlet("/EditUserInfo")
public class EditUserInfoServlet extends HttpServlet {
 private static final long serialVersionUID = 1L;
      
    /**
     * @see HttpServlet#HttpServlet()
     */
    public EditUserInfoServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

 /**
  * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
  */
 protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  request.setCharacterEncoding("UTF-8");
  response.setCharacterEncoding("UTF-8");
  ConDB conDB=new ConDB();
  LinkedList<String> ls=new LinkedList<>();
  ls.addLast(request.getParameter("name"));
  ls.addLast(request.getParameter("stuId"));
  ls.addLast(request.getParameter("phone"));
  ls.addLast(request.getParameter("stuName"));
  ls.addLast(request.getParameter("userName"));
  String sql="UPDATE user SET Name=?,stuId=?,phone=?,stuName=? WHERE userName=?";
  conDB.QueryAction(sql, ls);
  conDB.close();
 }

 /**
  * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
  */
 protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  // TODO Auto-generated method stub
  doGet(request, response);
 }

}

package org.fjzzy.webservlets;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.LinkedList;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.fjzzy.mysql_action.ConDB;

/**
 * Servlet implementation class FindFocusServlet
 */
@WebServlet("/FindFocus")
public class FindFocusServlet extends HttpServlet {
 private static final long serialVersionUID = 1L;
      
    /**
     * @see HttpServlet#HttpServlet()
     */
    public FindFocusServlet() {
        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
  request.setCharacterEncoding("UTF-8");
  response.setCharacterEncoding("UTF-8");
  ConDB conDB=new ConDB();
  String userName=request.getParameter("userName");
  String sql="SELECT focus FROM user WHERE userName=?";
  LinkedList<String> ls=new LinkedList<>();
  ResultSet rSet=conDB.QuerySelect(sql, userName);
  try {
   if(rSet.next()){
    response.setContentType("text/xml;charset=UTF-8");
    PrintWriter writer=response.getWriter();
    writer.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
    writer.write("<classlist>");
    String focusCode=rSet.getString("focus");
    String[] arr=focusCode.split(",");
    for(int i=0;i<arr.length;i++){
     if(arr[i].toString()!=null){
      ls.addLast(arr[i]);
     }
    }
    for(int i=0;i<ls.size();i++){
     String sqlFocus="SELECT * FROM class WHERE classId=?";
     ResultSet resultSet=conDB.QuerySelect(sqlFocus, ls.get(i));
     writer.write("<class>");
     if(resultSet.next()){
      writer.write("<className>"+resultSet.getString("className")+"</className>");
      writer.write("<classImg>"+resultSet.getString("classImg")+"</classImg>");
      writer.write("<classId>"+ls.get(i)+"</classId>");
     }
     writer.write("</class>");
    }
    writer.write("</classlist>");
   }
  } catch (SQLException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }finally{
   conDB.close();
  }
 }

 /**
  * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
  */
 protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  // TODO Auto-generated method stub
  doGet(request, response);
 }

}

package org.fjzzy.webservlets;

import java.io.IOException;
import java.sql.ResultSet;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.fjzzy.mysql_action.ConDB;

/**
 * Servlet implementation class FocusServlet
 */
@WebServlet("/Focus")
public class FocusServlet extends HttpServlet {
 private static final long serialVersionUID = 1L;

 /**
  * @see HttpServlet#HttpServlet()
  */
 public FocusServlet() {
  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
  request.setCharacterEncoding("UTF-8");
  response.setCharacterEncoding("UTF-8");
  String focusCode="";
  String classId = request.getParameter("classId");
  String focus = request.getParameter("focus");
  String userName = request.getParameter("userName");
  ConDB conDB = new ConDB();
  try {
   String sql = "SELECT * FROM user WHERE userName=?";
   ResultSet rSet = conDB.QuerySelect(sql, userName);
   if(rSet.next())
    focusCode = rSet.getString("focus");
   if (focus.equals("0")) {
    String sql1 = "UPDATE user SET focus=? WHERE userName=?";
    conDB.QueryAction(sql1, focusCode+classId + ",", userName);
   } else {
    
    String[] arr=focusCode.split(",");
    focusCode="";
    for(int i=0;i<arr.length;i++){
     if(!arr[i].equals(classId)&&arr[i].toString()!=null){
      focusCode+=arr[i]+",";
     }
    }
    String sql1="UPDATE user SET focus=? WHERE userName=?";
    conDB.QueryAction(sql1, focusCode, userName);
   }
  } catch (SQLException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  } finally {
   conDB.close();
   response.getWriter().print("1");
  }
 }

 /**
  * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
  *      response)
  */
 protected void doPost(HttpServletRequest request, HttpServletResponse response)
   throws ServletException, IOException {
  // TODO Auto-generated method stub
  doGet(request, response);
 }

}

package org.fjzzy.webservlets;

import java.io.IOException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.LinkedList;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.fjzzy.mysql_action.ConDB;

/**
 * Servlet implementation class ForgetServlets
 */
@WebServlet("/Forget")
public class ForgetServlet extends HttpServlet {
 private static final long serialVersionUID = 1L;
      
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ForgetServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

 /**
  * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
  */
 protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  request.setCharacterEncoding("UTF-8");
  response.setCharacterEncoding("UTF-8");
  String userName=request.getParameter("userName");
  String passWord=request.getParameter("passWord");
  String phone=request.getParameter("phone");
  LinkedList<String> ls=new LinkedList<>();
  String sql="SELECT * FROM user WHERE userName=?";
  String sql1="SELECT * FROM USER WHERE userName=? and phone=?";
  ConDB conDB=new ConDB();
  ls.addLast(userName);
  ls.addLast(phone);
  ResultSet rSet=conDB.QuerySelect(sql,userName);
  ResultSet rSet2=conDB.QuerySelect(sql1, ls);
  try {
   if(rSet.next()){
    if(rSet2.next()){
     String sqlUpdate="UPDATE `user` SET passWord=? WHERE userName=?";
     ls.clear();
     ls.addLast(passWord);
     ls.addLast(userName);
     conDB.QueryAction(sqlUpdate, ls);
     response.getWriter().print(rSet2.getString("imgUrl")+","+rSet2.getString("Name")+","+rSet2.getString("lv"));
    }else{
     response.getWriter().print("1");
    }
   }else{
    response.getWriter().print("0");
   }
  } catch (SQLException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }finally {
   conDB.close();
  }
 }

 /**
  * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
  */
 protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  // TODO Auto-generated method stub
  doGet(request, response);
 }

}

package org.fjzzy.webservlets;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.ResultSet;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.fjzzy.mysql_action.ConDB;

/**
 * Servlet implementation class IndexContentServlets
 */
@WebServlet("/IndexContent")
public class IndexContentServlet extends HttpServlet {
 private static final long serialVersionUID = 1L;
      
    /**
     * @see HttpServlet#HttpServlet()
     */
    public IndexContentServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

 /**
  * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
  */
 protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  response.setCharacterEncoding("UTF-8");
  request.setCharacterEncoding("UTF-8");
  String sql="SELECT * FROM class";
  ConDB conDB=new ConDB();
  ResultSet rSet=conDB.QuerySelect(sql);
  response.setContentType("text/xml;charset=UTF-8");
  PrintWriter writer=response.getWriter();
  try {
   writer.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
   writer.write("<classlist>");
   while(rSet.next()){
    writer.write("<class>");
    writer.write("<className majorName='"+rSet.getString("majorName")+"'>"+rSet.getString("className")+"</className>");
    writer.write("<classInfo>"+rSet.getString("classInfo")+"</classInfo>");
    writer.write("<classId>"+rSet.getInt("classId")+"</classId>");
    writer.write("<classImg>"+rSet.getString("classImg")+"</classImg>");
    writer.write("</class>");
   }
   writer.write("</classlist>");
  } catch (SQLException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
  finally{
   conDB.close();
  }
  
 }

 /**
  * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
  */
 protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  // TODO Auto-generated method stub
  doGet(request, response);
 }

}

package org.fjzzy.webservlets;

import java.io.IOException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.LinkedList;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.fjzzy.mysql_action.*;

/**
 * Servlet implementation class LoginServlets
 */
@WebServlet(description = "验证登录", urlPatterns = { "/Login" })
public class LoginServlet extends HttpServlet {
 private static final long serialVersionUID = 1L;
      
    /**
     * @see HttpServlet#HttpServlet()
     */
    public LoginServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

 /**
  * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
  */
 protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  request.setCharacterEncoding("UTF-8");
  response.setCharacterEncoding("UTF-8");
  String userName=request.getParameter("userName");
  String passWord=request.getParameter("passWord");
  ConDB conDB=new ConDB();
  String sql="SELECT * FROM user WHERE userName=? and passWord=?";
  LinkedList<String> ls=new LinkedList<>();
  ls.addLast(userName);
  ls.addLast(passWord);
  try {
   ResultSet rSet=conDB.QuerySelect(sql, ls);
   if(rSet.next()){
    response.getWriter().print(rSet.getString("imgUrl")+","+rSet.getString("Name")+","+rSet.getString("lv"));
   }else{
    response.getWriter().print("0");
   }
  } catch (SQLException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }finally{
   conDB.close();
  }
 }

 /**
  * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
  */
 protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  // TODO Auto-generated method stub
  doGet(request, response);
 }

}

package org.fjzzy.webservlets;

import java.io.IOException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.LinkedList;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.fjzzy.mysql_action.*;
/**
 * Servlet implementation class RegisterServlets
 */
@WebServlet(description = "注册检查", urlPatterns = { "/Register" })
public class RegisterServlet extends HttpServlet {
 private static final long serialVersionUID = 1L;
      
    /**
     * @see HttpServlet#HttpServlet()
     */
    public RegisterServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

 /**
  * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
  */
 protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  request.setCharacterEncoding("UTF-8");
  response.setCharacterEncoding("UTF-8");
  String userName=request.getParameter("userName");
  String passWord=request.getParameter("passWord");
  String phone=request.getParameter("phone");
  ConDB conDB=new ConDB();
  String sql="SELECT * FROM user WHERE userName=?";
  ResultSet rSet=conDB.QuerySelect(sql,userName);
  try {
   if(!rSet.next()){
    String sqlInsert="INSERT INTO `user` (userName,passWord,phone) VALUES (?,?,?)";
    LinkedList<String> ls=new LinkedList<>();
    ls.addLast(userName);
    ls.addLast(passWord);
    ls.addLast(phone);
    conDB.QueryAction(sqlInsert, ls);
    ResultSet rSet2=conDB.QuerySelect(sql,userName);
    if(rSet2.next()){
     response.getWriter().print(rSet2.getString("imgUrl")+","+rSet2.getString("Name")+","+rSet2.getString("lv"));
    }
   }else{
    response.getWriter().print("0");
   }
  } catch (SQLException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }finally {
   conDB.close();
  }
 }

 /**
  * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
  */
 protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  // TODO Auto-generated method stub
  doGet(request, response);
 }

}

package org.fjzzy.webservlets;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.ResultSet;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.fjzzy.mysql_action.ConDB;

/**
 * Servlet implementation class SearchClassServlet
 */
@WebServlet("/SearchClass")
public class SearchClassServlet extends HttpServlet {
 private static final long serialVersionUID = 1L;
      
    /**
     * @see HttpServlet#HttpServlet()
     */
    public SearchClassServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

 /**
  * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
  */
 protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  request.setCharacterEncoding("UTF-8");
  response.setCharacterEncoding("UTF-8");
  String key=request.getParameter("Key");
  String searchKey=request.getParameter("searchKey");
  String sql="";
  String value;
  if(searchKey!=""||searchKey==null){
   value="%"+searchKey+"%";
   sql="SELECT * FROM class WHERE className LIKE ? ";
  }else{
   value=key;
   sql="SELECT * FROM class WHERE majorName=?";
  }
  System.out.println(value);
  ConDB conDB=new ConDB();
  ResultSet rSet=conDB.QuerySelect(sql,value);
  try {
   if(!rSet.next()){
    response.getWriter().print(0);
   }else{
    rSet.previous();
    response.setContentType("text/xml;charset=UTF-8");
    PrintWriter writer=response.getWriter();
    writer.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
    writer.write("<classlist>");
    while(rSet.next()){
     writer.write("<class>");
     writer.write("<className majorName='"+rSet.getString("majorName")+"'>"+rSet.getString("className")+"</className>");
     writer.write("<classInfo>"+rSet.getString("classInfo")+"</classInfo>");
     writer.write("<classId>"+rSet.getInt("classId")+"</classId>");
     writer.write("<classImg>"+rSet.getString("classImg")+"</classImg>");
     writer.write("</class>");
    }
    writer.write("</classlist>");
   }
   
  } catch (SQLException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
  finally{
   conDB.close();
  }
 }

 /**
  * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
  */
 protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  // TODO Auto-generated method stub
  doGet(request, response);
 }

}

Jor1的主页 Jor1 | 初学一级 | 园豆:197
提问于:2017-06-07 22:52
< >
分享
所有回答(2)
1

太丑.别学了.换别的东西学吧.

吴瑞祥 | 园豆:29449 (高人七级) | 2017-06-07 22:56

 貌似要考试了,建议他去猪八戒。

支持(0) 反对(0) 花飘水流兮 | 园豆:13617 (专家六级) | 2017-06-07 23:07
0

好长啊,,

大水煮鱼 | 园豆:366 (菜鸟二级) | 2017-06-08 09:10
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册