📄 keepforlzs1.java
字号:
import java.io.*;
import java.text.*;
import java.util.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class KeepForLzs1 extends HttpServlet
{
String sLeibie;
String sLanmu;
public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws IOException
{
doGet(request,response);
}
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws IOException
{
HtmlOut htmlOut = new HtmlOut (response);
// 得到名字和口令
String name = CommonMethods.getParameterValue (request,"Name");
String pass = CommonMethods.getParameterValue (request,"Password");
if(name!=null&&pass!=null){
htmlOut.addCookie ("username",name);
htmlOut.addCookie ("password",pass);
}
else{//other we get it by cookie;
name = CommonMethods.GetUserName(request);
pass = CommonMethods.GetUserPass(request);
}
Person p=new Person();
p.setName (name);
System.out.println(p.getName());
System.out.println(pass);
if( p.getName ()==null || (!p.checkPassword(pass))
||(!p.IsSuperMan () &&!p.IsManager ()) )
{
htmlOut.setErrorID (htmlOut.SHOW_SIMPLE_MESSAGE ,"",
"请先登录!","/manage/");
htmlOut.outHtml();
return;
}
String sAct= CommonMethods.getParameterValue(request,"action");
DBOperater DB = new DBOperater("");
ResultSet rs;
if(sAct!=null && sAct.compareTo ( "add" )==0 ){
String sT=CommonMethods.getParameterValue (request,"title");
String sI=CommonMethods.getParameterValue (request,"info");
System.out.println(sI);
DB.executeUpdate("update hynews set newid=(newid + 1)");
DB.executeUpdate("insert into hynews values('"
+CommonMethods.DealWithSQLParameter
(sT)+"','"+CommonMethods.DealWithSQLParameter
(sI)+"',0)" );
}
if(sAct!=null && sAct.compareTo ( "delete" )==0 ){
String sID=CommonMethods.getParameterValue (request,"ID");
DB.executeUpdate("delete from hynews where newid="+sID);
}
if(sAct!=null && sAct.compareTo ( "make" )==0 ){
DB.close ();
//make html;
allTitles=new Vector (10,5);
allID=new Vector(10,5);
allInfo = new Vector(10,5);
makeHtml1();
htmlOut.setErrorID (htmlOut.SHOW_SIMPLE_MESSAGE,"",
"文件生成!", "/WebManage");
htmlOut.outHtml ();
return;
}
TemplateList tm=CommonMethods.getAddNewsTemplate();
if(tm==null){
DB.close ();
htmlOut.setErrorID (htmlOut.SHOW_SIMPLE_MESSAGE,"",
"莫板错误1!", "/WebManage");
htmlOut.outHtml ();
return;
}
SingleTemplate st = tm.searchTemplate ("ROOT");
if(st==null){
DB.close ();
htmlOut.setErrorID (htmlOut.SHOW_SIMPLE_MESSAGE,"",
"莫板错误!", "/WebManage");
htmlOut.outHtml ();
return;
}
String sKey;
String sTitle,sID;
for( int i=0;i<st.getKeyNum();i++ ){
sKey=st.getKeyAt (i);
htmlOut.addString ( st.getStringAt(i) );
if( sKey.compareTo ("内容")==0 ){
//out the news titles;
try{
rs = DB.executeQuery ("select * from hynews order by newid");
while( rs!=null&&rs.next() ){
sTitle=rs.getString (1);
sID=rs.getString (3);
htmlOut.addString (sTitle);
htmlOut.addString (" ");
htmlOut.addString ("<a href=\"KeepForLzs1?action=delete&ID="
+sID+"\">"+"删除</a>");
htmlOut.addString ("<br>");
}
}catch(Exception e){
}
};
if( sKey.compareTo ("cgi-path")==0 ){
htmlOut.addString (CommonMethods.sHostNameCGI);
};
}
htmlOut.addString (st.getEndString());
DB.close ();
htmlOut.outHtml ();
}
Vector allTitles,allID,allInfo;
boolean makeHtml1(){
DBOperater DB = new DBOperater("");
ResultSet rs;
String sTitle,sID,sInfo;
try{
rs = DB.executeQuery ("select * from hynews order by newid");
while( rs!=null&&rs.next() ){
sTitle=rs.getString (1);
sInfo=rs.getString (2);
sID=rs.getString (3);
if( sInfo==null )
sInfo="";
if( sTitle==null )
sTitle="";
allTitles.addElement(sTitle);
allID.addElement(sID);
allInfo.addElement(sInfo);
}
}
catch(Exception e){
}
DB.close ();
String sFile="";
TemplateList tm=CommonMethods.getTemplateDefault1();
if(tm==null){
return false;
}
SingleTemplate st = tm.searchTemplate ("ROOT");
if(st==null){
return false;
}
String sKey,sKey1;
for( int i=0;i<st.getKeyNum();i++ ){
sKey=st.getKeyAt (i);
sFile +=st.getStringAt(i) ;
if( sKey.compareTo ("allNews")==0 ){
//out the news titles;
System.out.println (allTitles.size ());
for( int n=0;n<allTitles.size ();n++){
sTitle=(String)allTitles.elementAt (n);
sInfo=(String)allInfo.elementAt(n);
sID=(String)allID.elementAt(n);
SingleTemplate st1 = tm.searchTemplate("news");
if( st1==null )
continue;
for( int j=0;j<st1.getKeyNum ();j++ ){
sKey1 = st1.getKeyAt(j);
sFile += st1.getStringAt(j);
if( sKey1.compareTo ("id")==0 ){
sFile += sID;
}
if( sKey1.compareTo ("title")==0 ){
sFile += sTitle;
}
}
sFile += st1.getEndString ();
System.out.println ("out one");
makeHtml2(sID,sTitle,sInfo);
}
};
}
sFile +=(st.getEndString());
String sPath=CommonMethods.sHtmlPath+
"b"+File.separatorChar +"Default.htm";
File f=new File(sPath);
if(f.exists ())
f.delete ();
CommonMethods.WriteToDisk(sFile.getBytes (),
sPath );
return true;
}
boolean makeHtml2(String sID1,String sTitle1,String sInfo1){
String sFile="";
TemplateList tm=CommonMethods.getTemplateDefault2();
if(tm==null){
return false;
}
SingleTemplate st = tm.searchTemplate ("ROOT");
if(st==null){
return false;
}
System.out.println(1);
String sKey,sKey1;
String sTitle,sID,sInfo;
for( int i=0;i<st.getKeyNum();i++ ){
sKey=st.getKeyAt (i);
sFile +=st.getStringAt(i) ;
if( sKey.compareTo ("title")==0 ){
System.out.println(2);
sFile +=sTitle1 ;
}
if( sKey.compareTo ("info")==0 ){
System.out.println(3);
sFile +=CommonMethods.makeHtmlString1(sInfo1 );
}
if( sKey.compareTo ("allNews")==0 ){
System.out.println(4);
//out the news titles;
for( int n=0;n<allTitles.size ();n++){
sTitle=(String)allTitles.elementAt (n);
sInfo=(String)allInfo.elementAt(n);
sID=(String)allID.elementAt(n);
SingleTemplate st1 = tm.searchTemplate("news");
if( st1==null )
continue;
for( int j=0;j<st1.getKeyNum ();j++ ){
sKey1 = st1.getKeyAt(j);
sFile += st1.getStringAt(j);
if( sKey1.compareTo ("id")==0 ){
sFile += sID;
}
if( sKey1.compareTo ("title")==0 ){
sFile += sTitle;
}
}
sFile += st1.getEndString ();
}
};
}
sFile +=(st.getEndString());
String sPath=CommonMethods.sHtmlPath+
"b"+File.separatorChar +"hybd"+File.separatorChar +"new_"+sID1+".htm";
File f=new File(sPath);
if(f.exists ())
f.delete ();
CommonMethods.WriteToDisk(sFile.getBytes (),
sPath );
return true;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -