📄 cardservlet.java
字号:
/*
* CardServlet.java
*/
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
/**
* The simplest possible servlet.
*
* @author Liyan
*/
//The class hand the Http request
public class CardServlet 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");
CardChannel cardChannel=new CardChannel();
System.out.println (flag);
if (flag==null)
{
//取得通讯录主模板:
TemplateList tempList=CommonMethods.getCard_MainTemplate();
if( tempList==null )
System.out.println("template error!");
cardChannel.makeCard_Main(p,tempList,htmlOut,"","");
} else {
if (flag.compareTo("insert")==0) //显示添加界面
{
//TemplateList tempList=CommonMethods.getCard_AddTemplate();
//cardChannel.makeCard_Add(p,tempList,new HtmlOuter(out));
response.sendRedirect("/CardAdd.htm");
}
if (flag.compareTo("add")==0) //通讯录入库
{
String tmpStr;
String[] selection=new String[24];
byte [] by;
for(int i=1;i<10;i++)
{
selection[i]="";
tmpStr= request.getParameter("a00"+i);
if (tmpStr!=null) {
by=tmpStr.trim().getBytes("8859_1");
tmpStr= new String(by);
selection[i]=tmpStr;
}
}
for(int i=10;i<=23;i++)
{
selection[i]="";
tmpStr= request.getParameter("a0"+i);
if (tmpStr!=null) {
by=tmpStr.trim().getBytes("8859_1");
tmpStr= new String(by);
selection[i]=tmpStr;
}
}
Card card=new Card();
card.clear();
//selection[9]="0";
if( selection[9]==null||selection[9]=="" ){
selection[9]="0";
}
card.setValues(p.getName(),selection[1], selection[2], selection[3],
selection[4], selection[5], selection[6],
selection[7], selection[8],
CommonMethods.GetInt(selection[9],10),
selection[10], selection[11],
selection[12], selection[13],
selection[14], selection[15],
selection[16], selection[17],
selection[18], selection[19],
selection[20], selection[21],
selection[22], selection[23]);
card.save();
card.clear();
String sContinue=request.getParameter("continue");
if(sContinue!=null) {
response.sendRedirect("CardServlet?flag=insert");
}else {
response.sendRedirect("CardServlet");
}
}
if (flag.compareTo("delete")==0) //删除通讯录
{
Card card=new Card();
int nLength=request.getParameterValues("single").length;
String[] dArray=new String[nLength];
dArray=request.getParameterValues("single");
for(int i=0;i<nLength;i++) {
if(dArray[i]==null)
if(dArray[i].compareTo("")==0)
dArray[i] = "0";
card.delete(p.getName(),dArray[i] );
card.clear();
}
response.sendRedirect("CardServlet");
}
if (flag.compareTo("search")==0) //查询功能
{
//out.println("查询结果:");
String sItem=request.getParameter("finditem");
String sValue=request.getParameter("findvalue");
sValue=CommonMethods.DealWithGBCodeOfRequest(sValue);
if(sItem.compareTo("sex")==0){
if(sValue.trim().compareTo("男")==0)
sValue="M";
if(sValue.trim().compareTo("女")==0)
sValue="F";
if(sValue.trim().compareTo("未知")==0||sValue.trim().compareTo("")==0)
sValue="U";
}
//out.println(sItem+sValue);
TemplateList tempList=CommonMethods.getCard_MainTemplate();
cardChannel.makeCard_Main(p,tempList,htmlOut,sItem,sValue);
}
if (flag.compareTo("edit")==0) //编辑功能
{
String sID=request.getParameter("ID");
TemplateList tempList=CommonMethods.getCard_EditTemplate();
if(sID==null||sID=="")
sID = "0";
cardChannel.makeCard_Edit(p,tempList,htmlOut,CommonMethods.GetInt(sID,10));
}
if (flag.compareTo("print")==0) //打印通讯录
{
}
}
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 + -