粘贴自己用
public class LogoutServlet extends HttpServlet {private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//处理注销请求
HttpSession session =request.getSession();
session.removeAttribute("user");//容器通知UserList类调用remove方法
response.setContentType("text/html");
response.setCharacterEncoding("utf-8");
PrintWriter out=response.getWriter();
out.println("<html>");
out.println(" <head>");
out.println(" <title>退出登录</title>");
out.println(" </head>");
out.println(" <body>");
out.println(" <br/>已退出登录!");
out.println(" <a href='login.html'>重新登录</a>");
out.println(" </body>");
out.println("</html>");
out.flush();
out.close();
}
--------------------编程问答-------------------- <%@page import="java.text.SimpleDateFormat"%>
<%@page import="java.util.Date"%>
<%@page import="com.niit.j2ee.guestbook.Message"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript">
function success()
{
alert("提交成功!");
}
</script>
</head>
<body>
<%@include file="common.jsp" %>
<%
request.setCharacterEncoding("utf-8");
%>
<jsp:setProperty property="*" name="message"/>
<%
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
message.setTime(sdf.format(new Date()));
message.setIp(request.getRemoteAddr());
//调用bean实例的方法
boolean result=dbmessage.addMessage(message);
if(result)
{
//显示成功
%>
<jsp:forward page="getmessagelist.jsp"></jsp:forward>
<%
}
else
{
//显示失败
%>
<h3>失败</h3>
<%
}
%>
</body>
</html> --------------------编程问答-------------------- @WebServlet("/GetBookListServlet")
public class GetBookListServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
String driver=null;
String url;
String user;
String pwd;
int i;
public GetBookListServlet() {
super();
// TODO Auto-generated constructor stub
}
@Override
public void init() throws ServletException {
ServletContext sc=getServletContext();
driver=sc.getInitParameter("bookdriver");
url=sc.getInitParameter("bookurl");
user=sc.getInitParameter("bookuser");
pwd=sc.getInitParameter("bookpassword");
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
Connection conn=null;
PreparedStatement st=null;
ResultSet rs=null;
response.setContentType("text/html");
response.setCharacterEncoding("utf-8");
request.setCharacterEncoding("utf-8");
PrintWriter out=response.getWriter();
try {
Class.forName(driver);
conn=DriverManager.getConnection(url,user,pwd);
String sql="select * from bookstore";
st=conn.prepareStatement(sql);
rs=st.executeQuery();
out.println("<html>");
out.println(" <head>");
out.println(" <title>booklist</title>");
out.println(" <script type='text/javascript' src='book.js'></script>");
out.println(" </head>");
out.println(" <body>");
out.println(" <form action='' method='post' id='formid'>");
out.println(" <input type='hidden' name='hiddenname' id='hiddenid'/>");
out.println(" <table border='1'>");
while(rs.next())
{
out.println(" <tr>");
out.println(" <td>");
out.println(" <input type='checkbox' name='checkbox' value='"+rs.getInt(1)+"'/>");
out.println(" </td>");
out.println(" <td>");
out.println(rs.getInt(1));
out.println(" </td>");
out.println(" <td>");
out.println(rs.getString(2));
out.println(" </td>");
out.println(" <td>");
out.println(rs.getString(3));
out.println(" </td>" );
out.println(" <td>");
out.println(rs.getString(4));
out.println(" </td>");
out.println(" <td>");
out.println(rs.getFloat(5));
out.println(" </td>");
out.println(" <td>");
out.println(rs.getInt(6));
out.println(" </td>");
out.println(" <td>");
out.println(rs.getString(7));
out.println(" </td>");
out.println(" <td>");
out.println(" <input type='button' onclick='bookupdate("+rs.getString(1)+")' value='修改'/>");
out.println(" </td>");
out.println(" <td>");
out.println(" <input type='button' onclick='bookdelete("+rs.getString(1)+")' value='删除'/>");
out.println(" </td>");
out.println(" </tr>");
}
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally
{
try {
if(rs!=null)
{
rs.close();
}
if(st!=null)
{
st.close();
}
if(conn!=null)
{
conn.close();
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
out.println(" </table>");
out.println(" <br/>");
out.println(" <input type='button'name='plshanchu' value='批量删除' onclick='shanchu()'/>");
out.println(" </form>");
out.println(" </body>");
out.println("</html>");
out.flush();
out.close();
}
}
--------------------编程问答-------------------- 啥情况!! --------------------编程问答-------------------- 粘贴自己用 --------------------编程问答-------------------- 自己用!
补充:Java , 非技术区