📄 openin.java
字号:
package org.myservlets;
import java.io.IOException;
import java.io.PrintWriter;
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 org.myJavabeans.DataConnection;
public class openIn extends HttpServlet {
/**
* 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 {
doPost(request, response);
}
/**
* 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 {
DataConnection ds = new DataConnection();
String t_id = request.getParameter("t_id");
String t_password = request.getParameter("t_password");
String t_name=ds.executename(t_id);
int i = ds.isAdmin(t_id, t_password);
if (i == 1) {//是管理员
request.setAttribute("t_name", t_name);
HttpSession session=request.getSession();
session.setAttribute("adminid",t_id);
request.getRequestDispatcher("/admin.jsp").forward(request,
response);
} else if(i==3){//是教师
request.setAttribute("t_name",t_name);
HttpSession session=request.getSession();
session.setAttribute("teacherid",t_id);
request.getRequestDispatcher("/teacher.jsp").forward(request,
response);
}else if(i==2){//密码错误
request.setAttribute("jsp", "open.jsp");
request.setAttribute("message",t_name+":您输入的密码不正确!");
request.getRequestDispatcher("/error.jsp").forward(request,
response);
}else{
request.setAttribute("jsp", "open.jsp");
request.setAttribute("message","没有此用户信息!");
request.getRequestDispatcher("/error.jsp").forward(request,
response);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -