粘贴自己用

djk1990 2011-11-13 11:14:16
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();

}
...全文
37 点赞 收藏 5
写回复
5 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
longyi008 2011-11-17
粘贴自己用
回复
z_f_p 2011-11-17
自己用!
回复
随风醉舞 2011-11-14
啥情况!!
回复
djk1990 2011-11-13
@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();


}

}
回复
djk1990 2011-11-13
<%@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>
回复
相关推荐
发帖
非技术区
创建于2007-09-28

2.3w+

社区成员

Java 非技术区
申请成为版主
帖子事件
创建了帖子
2011-11-13 11:14
社区公告
暂无公告