📄 bookmarkservlet.java
字号:
/*
* BookmarkServlet.java
*/
import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
/**
*
* @author Liyan
*/
//The class hand the Http request
public class BookmarkServlet extends HttpServlet {
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
{
HtmlOut htmlOut = new HtmlOut (response);
Person p=new Person();
p.setName (CommonMethods.GetUserName(request));
String pass = CommonMethods.GetUserPass (request);
if( p.getName ()==null || (!p.checkPassword(pass)) )
{
htmlOut.setErrorID (htmlOut.SHOW_SIMPLE_MESSAGE ,"",
"请先登录!","Login?action=reLog");
htmlOut.outHtml();
return;
}
String flag=request.getParameter("flag");
BookmarkChannel bookmarkChannel=new BookmarkChannel();
if (flag==null)
{
//取得书签主模板:
String sParentID=request.getParameter("parentID");
String sLink=request.getParameter("link");
//如果是点击一个书签的链接,就直接去
if(sLink!=null)
if(sLink.trim().length()!=0)
{
int nPlace=sLink.indexOf("//");
if(nPlace!=-1) sLink=sLink.substring(nPlace+2,sLink.length());
response.sendRedirect("//"+sLink);
}
TemplateList tempList=CommonMethods.getBookmark_MainTemplate();
bookmarkChannel.makeBookmark_Main(p,tempList,htmlOut,"parentID",
sParentID,"");
} else {
if (flag.compareTo("up")==0)
{
//取得书签主模板:
String sLink=request.getParameter("link");
TemplateList tempList=CommonMethods.getBookmark_MainTemplate();
bookmarkChannel.makeBookmark_Main(p,tempList,htmlOut,"parentID",
sLink,"");
}
if (flag.compareTo("insertLink")==0) //显示添加链接界面
{
//TemplateList tempList=CommonMethods.getCard_AddTemplate();
//cardChannel.makeCard_Add(p,tempList,new HtmlOuter(out));
String sName=CommonMethods.DealWithGBCodeOfRequest(request.getParameter("name"));
String sContent=CommonMethods.DealWithGBCodeOfRequest(request.getParameter("content"));
String sCurrentFolder=request.getParameter("currentFolder");
if(sName==null)
sName="";
if(sContent==null)
sContent="";
if(sCurrentFolder==null)
sCurrentFolder="0";
String sHtml="";
sHtml+="<table border=0 cellspacing=0 cellpadding=0 width=100%>";
sHtml+="<form name=ok action=\"BookmarkServlet?flag=add\" method=\"POST\" onsubmit=\"return checkLink(this)\">";
sHtml+="<input name=currentFolder type=hidden value="+sCurrentFolder+">";
sHtml+="<input name=attrib type=hidden value=link>";
sHtml+="<tr><td nowrap width=20% align=center><font color=0000aa>书签名称:</font></td>";
sHtml+="<td nowrap width=35%><input type=text size=25 name=name MAXLENGTH=10 value="+sName+"></td>";
sHtml+="<td nowrap width=10% align=center><font color=0000aa>网址:</font></td>";
sHtml+="<td nowrap width=35%><input type=text size=30 name=content MAXLENGTH=50 value="+sContent+"></td>";
sHtml+="</tr>";
sHtml+="</table>";
sHtml+="<table border=0 cellspacing=0 cellpadding=0 width=100%>";
sHtml+="<tr><td nowrap width=20% align=center><font color=0000aa>简介:</font></td>";
sHtml+="<td nowrap width=60%><input type=text name=addition size=45 MAXLENGTH=50></td>";
sHtml+="<td nowrap width=20%>";
sHtml+="<input type=submit value=\"添加\">";
sHtml+="<input type=reset> ";
sHtml+="</form> ";
sHtml+="</td></tr>";
sHtml+="</table>";
//htmlOut.addString (sHtml);
TemplateList templist;
templist=CommonMethods.getBookmark_MainTemplate();
bookmarkChannel.makeBookmark_Main(p,templist,htmlOut,"ParentID",sCurrentFolder,sHtml);
}
if (flag.compareTo("insertFolder")==0) //显示添加文件夹界面
{
String sCurrentFolder=request.getParameter("currentFolder");
String sHtml="";
sHtml+="<form name=ok action=\"BookmarkServlet?flag=add\" method=\"POST\" onsubmit=\"return checkFolder(this)\">";
sHtml+="<input name=currentFolder type=hidden value="+sCurrentFolder+">";
sHtml+="<input name=attrib type=hidden value=folder>";
sHtml+="<tr bgcolor=\"#FFFFFF\"> <td colspan=\"6\">";
sHtml+="<table border=0 cellpadding=0 cellspacing=0 width=\"100%\"><tr>";
sHtml+="<td align=middle noWrap width=\"20%\">目录名称:</td>";
sHtml+="<td noWrap width=\"60%\"><input maxlength=10 name=name size=45></td><td noWrap width=\"20%\">";
sHtml+="<div align=\"center\"><input type=submit value=添加 name=\"submit\">";
sHtml+="<input type=reset value=重置 name=\"reset\">";
sHtml+="</div></td></tr></table></form></td></tr>";
//htmlOut.addString (sHtml);
TemplateList templist;
templist=CommonMethods.getBookmark_MainTemplate();
bookmarkChannel.makeBookmark_Main(p,templist,htmlOut,"ParentID",sCurrentFolder,sHtml);
}
if (flag.compareTo("add")==0) //书签入库
{
String sBookmarkID=request.getParameter("bookmarkID");
String sName=CommonMethods.DealWithGBCodeOfRequest(request.getParameter("name"));
String sAttrib=request.getParameter("attrib");
String sParentID=request.getParameter("currentFolder");
String sContent=CommonMethods.DealWithGBCodeOfRequest(request.getParameter("content"));
String sAddition=CommonMethods.DealWithGBCodeOfRequest(request.getParameter("addition"));
if(sContent==null) sContent="";
if(sAddition==null) sAddition="";
if(sBookmarkID==null) sBookmarkID="0";
if(sParentID==null) sParentID="0";
Bookmark bookmark = new Bookmark();
bookmark.setValues(p.getName(),CommonMethods.GetInt(sBookmarkID,10),sName,sAttrib,CommonMethods.GetInt(sParentID,10),
sContent,sAddition);
bookmark.save();
bookmark.clear();
response.sendRedirect("BookmarkServlet?parentID="+sParentID);
}
if (flag.compareTo("delete")==0) //删除书签
{
String sParentID=request.getParameter("currentFolder");
Bookmark bookmark = new Bookmark();
int nLength=request.getParameterValues("single").length;
String[] dArray=new String[nLength];
dArray=request.getParameterValues("single");
for(int i=0;i<nLength;i++) {
//out.println(dArray[i]+"<br>");
if(dArray[i]==null||(dArray[i].compareTo("yes")==0))
dArray[i] = "0";
bookmark.delete(p.getName(),CommonMethods.GetInt(dArray[i],10));
bookmark.clear();
}
response.sendRedirect("BookmarkServlet?parentID="+sParentID);
}
if (flag.compareTo("edit")==0) //编辑功能
{
int nLength=request.getParameterValues("single").length;
String[] dArray=new String[nLength];
String sBookmarkID="";
dArray=request.getParameterValues("single");
if(dArray[0].compareTo("yes")==0)
sBookmarkID=dArray[1];
else
sBookmarkID=dArray[0];
String[] sArray=new String[7];
Bookmark bookmark = new Bookmark();
bookmark.setQuery("BookMarkID",sBookmarkID);
bookmark.query(p.getName());
if(bookmark.read()) {
sArray[0]=bookmark.getUserName();
sArray[1]=""+bookmark.getBookmarkId();
sArray[2]=bookmark.getName();
sArray[3]=bookmark.getAttrib();
sArray[4]=""+bookmark.getParentID();
sArray[5]=bookmark.getContent();
sArray[6]=bookmark.getAddition();
}
bookmark.clear();
//out.println("要编辑的属性是:"+sArray[3]+"<br>");
//根据不同的情况显示编辑界面:
TemplateList templist;
if(sArray[3].trim().compareTo("link")==0) {
templist=CommonMethods.getBookmark_EditLinkTemplate();
}
else
{
templist=CommonMethods.getBookmark_EditFolderTemplate();
}
bookmarkChannel.makeBookmark_Edit(p,templist,htmlOut,sArray);
}
if (flag.compareTo("moveto")==0) //移动书签选择目的地
{
int nLength=request.getParameterValues("single").length;
String[] dArray=new String[nLength];
String sBookmarkID="";
dArray=request.getParameterValues("single");
//根据不同的情况显示编辑界面:
String sHtml="";
sHtml+="<html><head><title>移动书签</title>";
sHtml+="<link rel=\"stylesheet\" href=\"/img/style.css\">";
sHtml+="</head>";
sHtml+="<body bgcolor=\"#e3e5e5\">";
sHtml+="请选择要移动到的目录:<br>";
sHtml+="<form action=\"BookmarkServlet?flag=move\" method=post>";
sHtml+="";
htmlOut.addString(sHtml);
Bookmark bookmark = new Bookmark();
bookmark.showFolder(p.getName(),0,0,"我的书签",htmlOut);
sHtml="<br><input type=submit value=确定>";
for(int i=0;i<nLength;i++)
if (dArray[i].compareTo("yes")!=0)
sHtml+="<br><input name=source type=hidden value="+dArray[i]+">";
sHtml+="";
sHtml+="</form>";
sHtml+="</body>";
sHtml+="</html>";
htmlOut.addString(sHtml);
htmlOut.outHtml ();
}
if (flag.compareTo("move")==0) //判断并进行移动
{
int nLength = request.getParameterValues("source").length;
String[] sSource = new String[nLength];
sSource = request.getParameterValues("source");
if(sSource!=null) {
htmlOut.addString("您要把:");
for(int i=0;i<nLength;i++)
htmlOut.addString(sSource[i]+"、");
String sDest=request.getParameter("dest");
if(sDest!=null) {
htmlOut.addString("移到:");
htmlOut.addString(sDest);
Bookmark bookmark = new Bookmark();
for(int i=0;i<nLength;i++) {
//干活
bookmark.move(p.getName(),sSource[i],sDest);
bookmark.clear();
}
}
}
htmlOut.outHtml ();
response.sendRedirect("BookmarkServlet");
}
}
htmlOut.outHtml ();
}
public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
{
doGet(request, response);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -