人法地,地法天,天法道,道法自然
分类: Java
2007-10-12 19:43:49
2. Servlet代码:(workmain.java)
package com.maye.suitem.login;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
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 com.maye.suitem.Conn.Conn;
import com.maye.suitem.Security.MessageMD5;
import com.maye.suitem.javabeans.Atea;
import com.maye.suitem.Config.System_config;
public class workmain extends HttpServlet {
/**
* The doGet method of the servlet.
*
* 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");
response.setCharacterEncoding("UTF-8");
request.setCharacterEncoding("UTF-8");
PrintWriter out = response.getWriter();
String action = request.getParameter("action");
if ("zhuxiao".equalsIgnoreCase(action)||"exit".equalsIgnoreCase(action)) {
HttpSession session=request.getSession(true);
session.invalidate();
RequestDispatcher rd = getServletContext().getRequestDispatcher("/index.jsp");
rd.forward(request, response);
}
}
/**
* The doPost method of the servlet.
*
* 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 {
request.setCharacterEncoding("UTF-8");
response.setContentType("text/xml; charset=UTF-8");
response.setCharacterEncoding("UTF-8");
response.setHeader("Cache-Control", "no-cache");
PrintWriter out = response.getWriter();
HttpSession session=request.getSession();
String action=request.getParameter("action");
String leix=request.getParameter("leix");
if("login".equals(action)&&"teacher".equals(leix)){
doTeacher(request,response);
}
if("login".equals(action)&&"checker".equals(leix)){
doChecker(request,response);
}
if("login".equals(action)&&"manager".equals(leix)){
doManager(request,response);
}
out.close();
}
注:以上只是部分代码(略)
chinaunix网友2008-09-10 14:15:41
http://www.sap99.com/ ,SAP免费资料下载 SAP99资料多多 http://www.sap99.com 有很多的学习资料,推荐一下,