📄 showzbgz.java
字号:
/**
* MakeStockInf.java
*
* 手工录入股票指数行情,并生成静态网页:
*/
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class ShowZBGZ extends HttpServlet
{
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
{
response.setContentType("text/html;charset=GB2312");
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);
if( p.getName ()==null || (!p.checkPassword(pass))
||(!p.IsSuperMan ()&&!p.IsManager ()) )
{
htmlOut.setErrorID (htmlOut.SHOW_SIMPLE_MESSAGE ,"",
"请先登录!","/manage/");
htmlOut.outHtml();
return;
}
String sFlag = request.getParameter("flag");
if(sFlag==null)
{
//显示添加界面:
showInterface(htmlOut);
}else{
//添加信息生成静态网页:
if(sFlag.compareTo("make")==0)
{
String sFileName=CommonMethods.sHtmlPath+"b"+File.separatorChar +"jrzx"+File.separatorChar +"jrzx_left.htm";
String sDate =CommonMethods.DealWithGBCodeOfRequest(request.getParameter("date"));
String[][] sStockIndex = new String[2][8];
for(int i=1;i<=8;i++)
{
sStockIndex[0][i-1]=request.getParameter("index_"+i);
sStockIndex[1][i-1]=request.getParameter("markup_"+i);
}
makeHtml(sFileName,sDate,sStockIndex);
htmlOut.setErrorID (htmlOut.SHOW_SIMPLE_MESSAGE ,"","已成功生成静态文件","/WebManage");
}
}
htmlOut.outHtml();
}
public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
{
doGet(request, response);
PrintWriter out = response.getWriter();
}
//添加界面:
public void showInterface(HtmlOut htmlOut)
{
TemplateList tList = TemplateList.getTemplate
(CommonMethods.sTemplateDir+"t_stockIndex.html");
if(tList==null){
System.out.println("Can't find "+File.separatorChar +"template"+File.separatorChar +"t_stockIndex.html!");
return;
}
SingleTemplate st = tList.searchTemplate("ROOT");
if(st==null){
System.out.println("Can't find the template!");
return;
}
int nKey = st.getKeyNum();
String sKey="";
for(int i=0;i<nKey;i++)
{
sKey = st.getKeyAt(i);
htmlOut.addString(st.getStringAt(i));
String sTmp="<input type=text name=";
for(int i2=1;i2<=8;i2++){
if(sKey.compareTo("index_"+i2)==0)
htmlOut.addString(sTmp+"index_"+i2+">");
if(sKey.compareTo("markup_"+i2)==0)
htmlOut.addString(sTmp+"markup_"+i2+">");
}
if(sKey.compareTo("date")==0)
htmlOut.addString(sTmp+"date>");
if(sKey.compareTo("script")==0){
SingleTemplate st2 = tList.searchTemplate("script");
if(st2==null){
System.out.println("Can't find the template!");
return;
}
htmlOut.addString(st2.getEndString());
}
if(sKey.compareTo("beginform")==0)
htmlOut.addString("<form name=ok><input type=hidden name=flag value=make>");
if(sKey.compareTo("endform")==0)
htmlOut.addString("<div align=center><input type=submit value=生成静态文件></div></form>");
}
htmlOut.addString(st.getEndString());
}
//要生成的静态界面:
public void makeHtml(String sFileName,String sDate,String[][] sStockIndex)
{
TemplateList tList = TemplateList.getTemplate
(CommonMethods.sTemplateDir+"t_stockIndex.html");
if(tList==null){
System.out.println("Can't find c:"+File.separatorChar +"template"+File.separatorChar +"t_stockIndex.html!");
return;
}
SingleTemplate st = tList.searchTemplate("ROOT");
if(st==null){
System.out.println("Can't find the template!");
return;
}
String html="";
int nKey = st.getKeyNum();
String sKey="";
for(int i=0;i<nKey;i++)
{
sKey = st.getKeyAt(i);
html+=st.getStringAt(i);
for(int i2=1;i2<=8;i2++){
if(sKey.compareTo("index_"+i2)==0)
html+=sStockIndex[0][i2-1];
if(sKey.compareTo("markup_"+i2)==0)
html+=sStockIndex[1][i2-1];;
}
if(sKey.compareTo("date")==0)
html+=sDate;
}
html+=st.getEndString();
try
{
FileWriter fw = new FileWriter(sFileName);
fw.write(html);
fw.close();
}catch(Exception ex){
System.out.println("WriteFile Error:"+ex.toString());
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -