package com.wzh.struts.action;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Timestamp;
import java.util.Date;
import java.util.List;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.wzh.dao.ManagerinfoDAO;
import com.wzh.dao.TeacherinfoDAO;
import com.wzh.po.Managerinfo;
import com.wzh.po.Teacherinfo;
import com.wzh.struts.form.*;
import com.wzh.util.MD5;
public class judge extends HttpServlet {
/**
*
*/
private static final long serialVersionUID = 1L;
/**
* Constructor of the object.
*/
public judge() {
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>");
if(request.getParameter("select1")!=null){
String str=new String();
if(((String)request.getParameter("select1")).equals("1")) str="t";
else if(((String)request.getParameter("select1")).equals("2")) str="m";
request.setAttribute("sign", str);
ServletContext context = getServletContext();
RequestDispatcher dispatcher = context.getRequestDispatcher("/add.jsp");
dispatcher.forward(request, response);
}
else if(request.getParameter("select2")!=null){
String str=new String();
if(((String)request.getParameter("select2")).equals("1")) str="t";
else if(((String)request.getParameter("select2")).equals("2")) str="m";
request.setAttribute("sign", str);
ServletContext context = getServletContext();
RequestDispatcher dispatcher = context.getRequestDispatcher("/update.jsp");
dispatcher.forward(request, response);
}
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 {
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>");
if(request.getParameter("name1")!=null){
String str=request.getParameter("name1");
StringBuffer strbuf=query(str);
request.setAttribute("result", strbuf.toString());
ServletContext context = getServletContext();
RequestDispatcher dispatcher = context.getRequestDispatcher("/result_search.jsp");
dispatcher.forward(request, response);
}
else if(request.getParameter("name2")!=null){
Teacherinfo teacher=new Teacherinfo();
TeacherinfoDAO dao=new TeacherinfoDAO();
teacher.setName(request.getParameter("name2"));
Timestamp now=new Timestamp(new Date().getTime());
teacher.setRegistrationtime(now);
teacher.setUpdatetime(now);
boolean sign=dao.save(teacher);
if(sign==true){
StringBuffer strbuf=new StringBuffer();
strbuf.append("Store data successfully!<br><br><br><p align=right><a href=add.jsp>Back</a></p>");
request.setAttribute("result", strbuf.toString());
ServletContext context = getServletContext();
RequestDispatcher dispatcher = context.getRequestDispatcher("/result_success.jsp");
dispatcher.forward(request, response);
}
else{
String str1="Database read error!";
request.setAttribute("errorinfo", str1);
ServletContext context = getServletContext();
RequestDispatcher dispatcher = context.getRequestDispatcher("/dataError.jsp");
dispatcher.forward(request, response);
}
}
else if(request.getParameter("name3")!=null){
StringBuffer str=new StringBuffer();
str.append(request.getParameter("name3").trim());
boolean sign=false;
for(int i=0;i<str.length()&&sign==false;i++){
char c=str.charAt(i);
if(!Character.isDigit(c)) sign=true;
}
if(sign||request.getParameter("name3").trim().length()==0){
response.sendRedirect("dataError.jsp");
}
else{
Teacherinfo teacher=new Teacherinfo();
TeacherinfoDAO dao=new TeacherinfoDAO();
teacher.setId(new Integer(request.getParameter("name3").trim()));
teacher.setName(request.getParameter("name6"));
Timestamp now=new Timestamp(new Date().getTime());
teacher.setUpdatetime(now);
boolean sign1=dao.update(teacher);
if(sign1==true){
StringBuffer strbuf=new StringBuffer();
strbuf.append("Update teacher's information successfully!<br><br><br><p align=right><a href=update.jsp>Back</a></p>");
request.setAttribute("result", strbuf.toString());
ServletContext context = getServletContext();
RequestDispatcher dispatcher = context.getRequestDispatcher("/result_success.jsp");
dispatcher.forward(request, response);
}
else{
String str1="Database read error!";
request.setAttribute("errorinfo", str1);
ServletContext context = getServletContext();
RequestDispatcher dispatcher = context.getRequestDispatcher("/dataError.jsp");
dispatcher.forward(request, response);
}
}
}
else if(request.getParameter("name4")!=null){
StringBuffer str=new StringBuffer();
str.append(request.getParameter("name4").trim());
boolean sign=false;
for(int i=0;i<str.length()&&sign==false;i++){
char c=str.charAt(i);
if(!Character.isDigit(c)) sign=true;
}
if(sign||request.getParameter("name4").trim().length()==0){
response.sendRedirect("dataError.jsp");
}
else{
int id=Integer.parseInt(str.toString().trim());
String tm=(String)request.getParameter("select3");
if(tm.equals("1")){
TeacherinfoDAO td=new TeacherinfoDAO();
boolean sign1=td.delete(id);
if(sign1==true){
StringBuffer strbuf=new StringBuffer();
strbuf.append("Delete teacher successfully!<br><br><br><p align=right><a href=delete.jsp>Back</a></p>");
request.setAttribute("result", strbuf.toString());
ServletContext context = getServletContext();
RequestDispatcher dispatcher = context.getRequestDispatcher("/result_success.jsp");
dispatcher.forward(request, response);
}
else{
String str1="Database read error!";
request.setAttribute("errorinfo", str1);
ServletContext context = getServletContext();
RequestDispatcher dispatcher = context.getRequestDispatcher("/dataError.jsp");
dispatcher.forward(request, response);
}
}
else if(tm.equals("2")){
ManagerinfoDAO md=new ManagerinfoDAO();
boolean sign1=md.delete(id);
if
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
从前的课程设计,由于当时编码没有统一,所以页面只能用英文的,望见谅。 利用servlet hibernate和struts做的web工程。使用的数据库SQL2000。 用法:首先打上SQL2000的SP4补丁包用来打开1433端口。在SQL2000中附加压缩包中的数据库。login.jsp为登录页面,可以用数据库中的用户登陆,也可以用wangzhenhua这个用户登录,密码是123。数据库中的密码是通过md5加密的,不是真实的密码,所以需要用上面的用户对数据库进行初始化。
资源推荐
资源详情
资源评论
收起资源包目录
Java大作业_hibernate+struts+servlet.rar (65个子文件)
teacher_Data.MDF 1024KB
wzh_sh
.project 2KB
.settings
.jsdtscope 500B
org.eclipse.jdt.core.prefs 334B
org.eclipse.wst.jsdt.ui.superType.container 49B
org.eclipse.wst.jsdt.ui.superType.name 6B
.mymetadata 291B
WebRoot
login.jsp 553B
function.jsp 1KB
WEB-INF
struts-tiles.tld 8KB
.struts-config.mex 1KB
web.xml 1KB
struts-config.xml 922B
struts-bean.tld 9KB
struts-nested.tld 70KB
struts-html.tld 72KB
struts-logic.tld 14KB
validator-rules.xml 13KB
lib
msbase.jar 225KB
mssqlserver.jar 48KB
msutil.jar 22KB
classes
com
wzh
dao
TeacherinfoDAO.class 3KB
ManagerinfoDAO.class 3KB
struts
action
judge.class 10KB
ManagerAction.class 2KB
form
ManagerForm.class 1KB
TeacherForm.class 2KB
ApplicationResources.properties 81B
po
Teacherinfo.class 1KB
Teacherinfo.hbm.xml 1013B
Managerinfo.hbm.xml 808B
Managerinfo.class 1KB
factory
HibernateSessionFactory.class 2KB
util
testdata.class 525B
MD5.class 5KB
hibernate.cfg.xml 977B
index.jsp 834B
META-INF
MANIFEST.MF 36B
result_success.jsp 488B
error.html 628B
add.jsp 2KB
update.jsp 3KB
result_search.jsp 654B
search.jsp 765B
dataError.jsp 688B
delete.jsp 1KB
.myeclipse
src
com
wzh
dao
ManagerinfoDAO.java 2KB
TeacherinfoDAO.java 2KB
struts
action
judge.java 14KB
ManagerAction.java 2KB
form
TeacherForm.java 2KB
ManagerForm.java 2KB
ApplicationResources.properties 81B
po
Managerinfo.java 916B
Teacherinfo.hbm.xml 1013B
Managerinfo.hbm.xml 808B
Teacherinfo.java 1KB
factory
HibernateSessionFactory.java 3KB
util
MD5.java 6KB
testdata.java 269B
hibernate.cfg.xml 977B
.mystrutsdata 254B
.classpath 772B
.myhibernatedata 543B
teacher_Log.LDF 1024KB
共 65 条
- 1
资源评论
wangzhenhua1020
- 粉丝: 2
- 资源: 4
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- sql server 不同服务器之间数据库同步.zip
- 始终加密(Always Encrypted)在SQL Server中的应用.pdf
- matplotlib详细介绍(Python的2D绘图库)
- 超市管理系统java源代码+数据库100%好用.zip
- 非常好的点餐系统全部项目资料100%好用.zip
- 这个仓库包含多个包含Spring Boot的智能车示例,涵盖了各种功能和用例,适合学习和参考
- 非常好的会议预约管理系统源代码资料100%好用.zip
- 功能齐全的任务管理系统的设计方案,涵盖了基本的CRUD操作、用户管理、基本的安全控制以及前后端分离的设计
- 超市进销管理系统源代码资料.zip
- web大作业vue+springboot前后端分离项目源代码.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功