Merge remote-tracking branch 'remotes/origin/master' into wlf

# Conflicts:
#	src/servlet/account/Register.java
wlf
wlf 6 years ago
commit 074cef61da

File diff suppressed because it is too large Load Diff

@ -17,10 +17,18 @@
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="jdk" jdkName="11" jdkType="JavaSDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" scope="PROVIDED" name="Tomcat 8.5.37" level="application_server_libraries" />
<orderEntry type="library" exported="" name="lib" level="project" />
<orderEntry type="library" exported="" scope="PROVIDED" name="Tomcat 9.0.13" level="application_server_libraries" />
<orderEntry type="module-library" exported="">
<library>
<CLASSES>
<root url="jar://$MODULE_DIR$/out/artifacts/GDMS_war_exploded/WEB-INF/lib/tomcat-jdbc.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
</component>
</module>

@ -17,9 +17,8 @@ public class DownloadFile extends Operation{
String field = core.operation.utils.Utils.getFileField(table);
List<String> ls = new ArrayList<>();
ls.add(field);
ResultSet rs = DBManagement.select(ls,table,limits,0,1);
rs.next();
String filePath = rs.getString(0);
List<String[]> resultLs = DBManagement.select(ls,table,limits,0,1);
String filePath = resultLs.get(0)[0];
File file = new File(filePath);
this.getOptions().put("file",file);
return this.getOptions();

@ -17,17 +17,7 @@ public class Search extends Operation {
Map<String, String> limits = (Map<String, String>)this.getOptions().get("limits");
int start = (int)this.getOptions().get("start");
int end = (int)this.getOptions().get("end");
ResultSet rs = DBManagement.select(fields,table,limits,start,end);
ResultSetMetaData rsm = rs.getMetaData() ;
int columnCount = rsm.getColumnCount();
List<String[]> ls = new ArrayList<>();
while(rs.next()){
String[] s = new String[columnCount];
for(int i=0;i<columnCount;i++){
s[i] = rs.getString(i);
}
ls.add(s);
}
List<String[]> ls = DBManagement.select(fields,table,limits,start,end);
this.getOptions().put("result",ls);
return this.getOptions();
}

@ -28,9 +28,8 @@ public class UploadFileOperation extends Operation {
List<String> ls = new ArrayList<>();
ls.add(field);
ResultSet rs = DBManagement.select(ls,table,limits,0,1);
rs.next();
String lastFilePath = rs.getString(0);
List<String[]> resultLs = DBManagement.select(ls,table,limits,0,1);
String lastFilePath = resultLs.get(0)[0];
new File(lastFilePath).delete();
DBManagement.update(table,vMap,limits);
return this.getOptions();

@ -1,22 +1,46 @@
package core.process;
import core.operation.Select;
import error.GExcptInit;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class C_StudentSelectTeacher extends core.process.Process {
public void select(String studentID,String teacherID)throws Exception{
public class C_StudentSelectTeacher extends TempProcess {
String studentId;
String teacherId;
public void select()throws Exception{
if(!check()) throw new GExcptInit("ID Attrs init error!");
Select select=new Select();
select.setOptions(new HashMap<>());
String student_id=studentID;
select.addOptions("student_id",student_id);
String teacher_id=teacherID;
select.addOptions("teacher_id",teacher_id);
select.addOptions("student_id",this.getStudentId());
select.addOptions("teacher_id",this.getTeacherId());
Map<String,Object> options=select.execute(null);
}
protected boolean check() {
if(this.getStudentId()==null||this.getTeacherId()==null)
return false;
return true;
}
public String getTeacherId() {
return teacherId;
}
public void setTeacherId(String teacherId) {
this.teacherId = teacherId;
}
public String getStudentId() {
return studentId;
}
public void setStudentId(String studentId) {
this.studentId = studentId;
}
}

@ -0,0 +1,4 @@
package core.process;
public class C_StudentUploadOpeningReport {
}

@ -1,33 +1,46 @@
package core.process;
import core.operation.Select;
import error.GExcptInit;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class C_TeacherSelectStudent extends Process {
List<String> list;
public C_TeacherSelectStudent clone(){
C_TeacherSelectStudent tst = new C_TeacherSelectStudent();
tst.setInfo( this.getInfo());
List<String> list = new ArrayList<>();
for(String s:this.list){
list.add(new String(s));
}
return null;
}
public void select(String teacherID,String studentID)throws Exception{
public class C_TeacherSelectStudent extends TempProcess {
String studentId;
String teacherId;
public void select()throws Exception{
if(!check()) throw new GExcptInit("ID Attrs init error!");
Select select=new Select();
select.setOptions(new HashMap<>());
String teacher_id=teacherID;
select.addOptions("teacher_id",teacher_id);
String student_id=studentID;
select.addOptions("student_id",student_id);
select.addOptions("teacher_id",this.getTeacherId());
select.addOptions("student_id",this.getStudentId());
Map<String,Object> options=select.execute(null);
}
protected boolean check() {
if(this.getStudentId()==null||this.getTeacherId()==null)
return false;
return true;
}
public String getTeacherId() {
return teacherId;
}
public void setTeacherId(String teacherId) {
this.teacherId = teacherId;
}
public String getStudentId() {
return studentId;
}
public void setStudentId(String studentId) {
this.studentId = studentId;
}
}

@ -30,7 +30,7 @@ public class ProcessManagement {
//Map<graduation_design_id.x_status,status>
public static Map<String,Character> getStatus(User user){
Map<String,String> userTables = DBManagement.getUserTables(user.getType());
Map<String,String> userTables = DBManagement.getUserStatusTables(user.getType());
String graduationDesignId = null;
for(Map.Entry<String,String> entry:userTables.entrySet()){
String[] ti = entry.getKey().split(".");

@ -20,7 +20,7 @@ import static dao.DBManagement.userTables;
public interface AccountManagement {
static User login(String id, String password) throws Exception {
ResultSet rs = null;
List<String[]> ls = null;
String userType = null;
for(String userTable:userTables){
List<String> columns = new ArrayList<>();
@ -28,26 +28,22 @@ public interface AccountManagement {
Map<String,String> limits = new HashMap<>();
limits.put("id",id);
try {
rs = DBManagement.select(columns,userTable,limits,0,1);
ls = DBManagement.select(columns,userTable,limits,0,1);
} catch (Exception e) {
throw new GExcptSQL("QUERY\n\t"+id+"\nfailure");
}
if(rs!=null){
if(ls.size()!=0){
userType = userTable;
break;
}
}
if(rs==null){
throw new GExcptAccount("id "+id+"don't exists");
}
rs.next();
if(!rs.getString(2).equals(password))
String[] userInfo = ls.get(0);
if(!userInfo[1].equals(password))
throw new GExcptAccount("password wrong");
Map<String, String> vMap = new HashMap<>();
ResultSetMetaData rsm = rs.getMetaData();
rs.next();
for(int i=0;i<rsm.getColumnCount();i++){
vMap.put(rsm.getCatalogName(i),rs.getString(i));
String[] info = DBManagement.getUserInfoTables(userType);
for(int i=0;i<userInfo.length;i++){
vMap.put(info[i],userInfo[i]);
}
return createUser(userType,vMap);
}

@ -1,10 +1,10 @@
package dao;
import java.sql.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import error.GExcptSQL;
import gdms.Configuration;
import org.apache.tomcat.jdbc.pool.DataSource;
@ -29,6 +29,32 @@ public class DBManagement {
"graduation_design_reply",
"graduation_design_reply_opinion_record_score"
};
public static String[] studentInfo = {
"id",
"password",
"name",
"e_mail_location",
"phone_number",
"grade",
"profession_code"
};
public static String[] teacherInfo = {
"id",
"password",
"name",
"e_mail_location",
"phone_number",
"job_title",
"education",
"profession_code"
};
public static String[] administratorInfo = {
"id",
"password",
"name",
"e_mail_location",
"phone_number"
};
//<table1.x_id,table2.x_status>
public static Map<String,String> graduationDesignStudentTables = new HashMap<>(){
{
@ -79,7 +105,7 @@ public class DBManagement {
}
return null;
}
public static Map<String,String> getUserTables(String userType){
public static Map<String,String> getUserStatusTables(String userType){
if(userType.equals("student")){
return graduationDesignStudentTables;
}
@ -88,7 +114,18 @@ public class DBManagement {
}
return null;
}
public static String[] getUserInfoTables(String userType){
if(userType.equals("administrator")){
return administratorInfo;
}
if(userType.equals("student")){
return studentInfo;
}
if(userType.equals("teacher")){
return teacherInfo;
}
return null;
}
public static void delete(String table, Map<String,String> limits) throws GExcptSQL {
Delete delete = new Delete(table, limits);
String sql = delete.getSQL();
@ -99,7 +136,7 @@ public class DBManagement {
String sql = insert.getSQL();
update(sql);
}
public static ResultSet select(List<String> columns, String table, Map<String,String> limits, int startRow, int endRow) throws Exception {
public static List<String[]> select(List<String> columns, String table, Map<String,String> limits, int startRow, int endRow) throws Exception {
Select select = new Select(columns,table,limits,startRow,endRow);
String sql = select.getSQL();
return query(sql);
@ -109,15 +146,24 @@ public class DBManagement {
String sql = update.getSQL();
update(sql);
}
public static ResultSet query(String sql) throws Exception {
public static List<String[]> query(String sql) throws Exception {
if(!ifInit) return null;
ResultSet rs = null;
List<String[]> ls;
Connection con = null;
try{
con = DBManagement.getConnection();
Statement stmt = con.createStatement();
rs = stmt.executeQuery(sql);
System.out.println(rs);
ResultSet rs = stmt.executeQuery(sql);
ResultSetMetaData rsm = rs.getMetaData() ;
int columnCount = rsm.getColumnCount();
ls = new ArrayList<>();
while(rs.next()){
String[] s = new String[columnCount];
for(int i=0;i<columnCount;i++){
s[i] = rs.getString(i+1);
}
ls.add(s);
}
} catch (SQLException e) {
throw new GExcptSQL("Connect Failure");
}finally {
@ -129,7 +175,7 @@ public class DBManagement {
}
}
}
return rs;
return ls;
}
public static void update(String sql) throws GExcptSQL {
if(!ifInit) return;

@ -0,0 +1,7 @@
package error;
public class GExcptInit extends GExcpt {
public GExcptInit(String info) {
super(info);
}
}

@ -0,0 +1,28 @@
package filter;
import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@WebFilter(filterName = "OnlineCheck",urlPatterns = "/home.jsp")
public class OnlineCheck implements Filter {
public void destroy() {
}
public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws ServletException, IOException {
HttpServletRequest request = (HttpServletRequest) req;
if(request.getSession().getAttribute("user")==null){
HttpServletResponse response = (HttpServletResponse) resp;
response.sendRedirect("/login.jsp");
return;
}
chain.doFilter(req, resp);
}
public void init(FilterConfig config) throws ServletException {
}
}

@ -11,14 +11,12 @@ import java.util.Map;
public class test {
public static void main(String[] args){
String student_id = "001";
String teacher_id = "002";
core.process.Process p = new C_StudentSelectTeacher();
try {
((C_StudentSelectTeacher) p).select(student_id,teacher_id);
} catch (Exception e) {
e.printStackTrace();
}
int i=0;
do{
i++;
System.out.println(i);
}while(i<3);
List<String> list = new ArrayList<>();
list.add("q");
list.add("w");

@ -13,12 +13,13 @@ import java.io.IOException;
public class S_StudentSelectTeacher extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
super.doPost(request, response);
String student_id=request.getParameter("id");
String teacher_id=request.getParameter("id");
User user=(User)request.getSession().getAttribute("user");
String teacher_id=user.getId();
String student_id=user.getId();
try {
new C_StudentSelectTeacher().select(student_id,teacher_id);
C_StudentSelectTeacher test=new C_StudentSelectTeacher();
test.setTeacherId(teacher_id);
test.setStudentId(student_id);
} catch (Exception e) {
e.printStackTrace();
}

@ -13,11 +13,13 @@ import java.io.IOException;
public class S_TeacherSelectStudent extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
super.doPost(request, response);
String teacher_id=request.getParameter("id");
String student_id=request.getParameter("id");
User user=(User)request.getSession().getAttribute("user");
String student_id=user.getId();
String teacher_id=user.getId();
try {
new C_TeacherSelectStudent().select(teacher_id,student_id);
C_TeacherSelectStudent test=new C_TeacherSelectStudent();
test.setTeacherId(teacher_id);
test.setStudentId(student_id);
} catch (Exception e) {
e.printStackTrace();
}

@ -0,0 +1,15 @@
package servlet.Submit;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
public class S_ScoreSubmit extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
super.doPost(request, response);
String score = request.getParameter("score");
}
}

@ -0,0 +1,21 @@
package servlet.Submit;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
public class S_StudentFillTopicInformation extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
super.doPost(request, response);
String content1=new String(request.getParameter("text").getBytes("ISO8859-1"),"UTF-8");
String content2=request.getParameter("score");
try {
} catch (Exception e) {
e.printStackTrace();
}
}
}

@ -0,0 +1,43 @@
package servlet.Submit;
import core.user.User;
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.io.IOException;
import java.util.UUID;
@WebServlet("/upload")
@MultipartConfig
//学生id+文件
public class S_StudentUploadOpeningReport extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
super.doPost(request, response);
User user=(User) request.getSession().getAttribute("user");
String student_id=user.getId();
try {
//获取上传的文件
Part part=request.getPart("file");
//获取请求的信息
String name=part.getHeader("content-disposition");
//获取上传文件的目录
String root=request.getServletContext().getRealPath("/upload");
request.setAttribute("info", "上传文件成功");
} catch (Exception e) {
e.printStackTrace();
request.setAttribute("info", "上传文件失败");
}
request.getRequestDispatcher("/upload.jsp").forward(request, response);
}
}

@ -1,5 +1,6 @@
package servlet.Submit;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
@ -12,5 +13,11 @@ public class S_Submit extends HttpServlet {
super.doPost(request, response);
String content=new String(request.getParameter("text").getBytes("ISO8859-1"),"UTF-8");
String score=request.getParameter("score");
try {
} catch (Exception e) {
e.printStackTrace();
}
}
}

@ -0,0 +1,44 @@
package servlet.account;
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 core.user.Student;
import core.user.User;
import core.user.utils.AccountManagement;
import error.GExcptAccount;
import error.GExcptSQL;
@WebServlet("/login")
public class S_Login extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String id=request.getParameter("id");
String password=request.getParameter("password");
User user = null;
try {
user = AccountManagement.login(id,password);
} catch (GExcptSQL | SQLException gExcptSQL) {
gExcptSQL.printStackTrace();
response.sendRedirect("/op_fail.jsp");
return;
} catch (GExcptAccount gExcptAccount) {
gExcptAccount.printStackTrace();
response.sendRedirect("/op_fail.jsp");
return;
} catch (Exception e) {
e.printStackTrace();
response.sendRedirect("/op_fail.jsp");
return;
}
request.getSession().setAttribute("user",user);
response.sendRedirect("/home.jsp");
return;
}
}

@ -10,39 +10,40 @@ import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
@WebServlet("/register")
public class S_Register extends HttpServlet {
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
super.doPost(request, response);
Map<String,String> user_info=new HashMap<>();
String id=request.getParameter("id");
user_info.put("id",id);
String name=request.getParameter("name");
user_info.put("name",name);
String e_mail_location=request.getParameter("e_mail_location");
user_info.put("e_mail_location",e_mail_location);
String e_mail=request.getParameter("e_mail_location");
user_info.put("e_mail_location",e_mail);
String phone_number=request.getParameter("phone_number");
user_info.put("phone_number",phone_number);
String password=request.getParameter("password");
user_info.put("password",password);
String userType = request.getParameter("userType");
User user=null;
try {
String Identity=request.getParameter("Identity");
user = AccountManagement.register(Identity,user_info);
user = AccountManagement.register(userType,user_info);
} catch (GExcptSQL gExcptSQL) {
gExcptSQL.printStackTrace();
response.sendRedirect("/op_fail.jsp");
} catch (GExcptAccount gExcptAccount) {
gExcptAccount.printStackTrace();
response.sendRedirect("/op_fail.jsp");
} catch (Exception e) {
e.printStackTrace();
response.sendRedirect("/op_fail.jsp");
}
//注册失败
request.getSession().setAttribute("User",user);
request.getRequestDispatcher("/home.jsp").forward(request,response);
request.getSession().setAttribute("user",user);
response.sendRedirect("/home.jsp");
return;
}
}

@ -1,37 +0,0 @@
package servlet.account;
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 core.user.Student;
import core.user.User;
import core.user.utils.AccountManagement;
import error.GExcptAccount;
import error.GExcptSQL;
@WebServlet("/login")
public class login extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String id=request.getParameter("id");
String password=request.getParameter("password");
User user = null;
try {
user = AccountManagement.login(id,password);
} catch (GExcptSQL | SQLException gExcptSQL) {
gExcptSQL.printStackTrace();
} catch (GExcptAccount gExcptAccount) {
gExcptAccount.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
request.getSession().setAttribute("user",user);
request.getRequestDispatcher("/home.jsp").forward(request,response);
}
}

@ -40,7 +40,7 @@
</div>
<div class="register-cont">
<form method="post" action="login">
<form method="post" action="register">
<input class="register-input-text sno-text" type="text" name="id"
placeholder="学号或职工号">
<input class="register-input-text password-text" type="password" name="password"
@ -53,7 +53,7 @@
placeholder="请输入电话">
<input class="register-input-text check-password-text" type="password" name="password-check"
placeholder="请确认密码">
<select class="id-check" name="usertype">
<select class="id-check" name="userType">
<option value="">身份</option>
<option value="student">学生</option>
<option value="teacher">老师</option>

Loading…
Cancel
Save