欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久

打開(kāi)APP
userphoto
未登錄

開(kāi)通VIP,暢享免費電子書(shū)等14項超值服

開(kāi)通VIP
Velocity 的應用示例

Velocity 的介紹請參考 Velocity -- Java Web 開(kāi)發(fā)新技術(shù)。這里是它的一個(gè)應用示例。

這個(gè)例子參照了 PHP-Nuke 的結構, 即所有 HTTP 請求都以 http://www.some.com/xxx/Modules?name=xxx&

arg1=xxx&

bbb=xxx 的形式進(jìn)行處理。例子中所有文件都是 .java 和 .html , 沒(méi)有其他特殊的文件格式。除了 Modules.java 是 Java Servlet, 其余的 .java 文件都是普通的 Java Class.

所有 HTTP 請求都通過(guò) Modules.java 處理。Modules.java 通過(guò) Velocity 加載 Modules.htm。 Modules.htm 有頁(yè)頭,頁(yè)腳,頁(yè)左導航鏈接,頁(yè)中內容幾個(gè)部分。其中頁(yè)頭廣告、頁(yè)中內容是變化部分。頁(yè)頭廣告由 Modules.java 處理,頁(yè)中內容部分由 Modules.java dispatch 到子頁(yè)面類(lèi)處理。

1) Modules.java

import javax.servlet.*;

import javax.servlet.http.*;

import org.apache.velocity.*;

import org.apache.velocity.context.*;

import org.apache.velocity.exception.*;

import org.apache.velocity.servlet.*;

import commontools.*;

public class Modulesextends VelocityServlet

{

public Template handleRequest(HttpServletRequest request,HttpServletResponse response,Context context)

{

//initresponse.setContentType("text/html;

charset=UTF-8");

response.setCharacterEncoding("utf-8");

//prepare function pageProcessSubPage page = null;

ProcessSubPage mainPage = new HomeSubPage();

String requestFunctionName = (String) request.getParameter("name");

boolean logined = false;

String loginaccount = (String) request.getSession(true).getAttribute("loginaccount");

if (loginaccount != null)

{

logined = true;

}

//default page is mainpagepage = mainPage;

if (requestFunctionName == null||requestFunctionName.equalsIgnoreCase("home"))

{

page = mainPage;

}

//no login , can use these pageelse if (requestFunctionName.equalsIgnoreCase("login"))

{

page = new LoginProcessSubPage();

}

else if (requestFunctionName.equalsIgnoreCase("ChangePassword"))

{

page = new ChangePasswordSubPage();

}

else if (requestFunctionName.equalsIgnoreCase("ForgetPassword"))

{

page = new ForgetPassword();

}

else if (requestFunctionName.equalsIgnoreCase("about"))

{

page = new AboutSubPage();

}

else if (requestFunctionName.equalsIgnoreCase("contact"))

{

page = new ContactSubPage();

}

//for other page, need login firstelse if (logined == false)

{

page = new LoginProcessSubPage();

}

else if (requestFunctionName.equalsIgnoreCase("listProgram"))

{

page = new ListTransactionProgramSubPage();

}

else if (requestFunctionName.equalsIgnoreCase("ViewProgramItem"))

{

page = new ViewTransactionProgramItemSubPage();

}

else if (requestFunctionName.equalsIgnoreCase("UpdateProgramObjStatus"))

{

page = new UpdateTransactionProgramObjStatusSubPage();

}

else if (requestFunctionName.equalsIgnoreCase("Search"))

{

page = new SearchSubPage();

}

//check if this is administratorelse if (Utilities.isAdministratorLogined(request))

{

//Utilities.debugPrintln("isAdministratorLogined : true");

if (requestFunctionName.equalsIgnoreCase("usermanagement"))

{

page = new UserManagementSubPage();

}

else if (requestFunctionName.equalsIgnoreCase("UploadFiles"))

{

page = new UploadFilesSubPage();

}

else if (requestFunctionName.equalsIgnoreCase("DownloadFile"))

{

page = new DownloadFileSubPage();

}

else if (requestFunctionName.equalsIgnoreCase("Report"))

{

page = new ReportSubPage();

}

}

else

{

//no right to access.//Utilities.debugPrintln("isAdministratorLogined : false");

page = null;

}

//Utilities.debugPrintln("page : " + page.getClass().getName());

if(page != null)

{

context.put("function_page",page.getHtml(this, request, response, context));

}

else

{

String msg = "Sorry, this module is for administrator only.

You are not administrator.";

context.put("function_page",msg);

}

context.put("page_header",getPageHeaderHTML());

context.put("page_footer",getPageFooterHTML());

Template template = null;

try

{

template = getTemplate("/templates/Modules.htm");

//good

}

catch (ResourceNotFoundException rnfe)

{

Utilities.debugPrintln("ResourceNotFoundException 2");

rnfe.printStackTrace();

}

catch (ParseErrorException pee)

{

Utilities.debugPrintln("ParseErrorException2 " + pee.getMessage());

}

catch (Exception e)

{

Utilities.debugPrintln("Exception2 " + e.getMessage());

}

return template;

}

/** * Loads the configuration information and returns that information as a Properties, e * which will be used to initializ the Velocity runtime. */protected java.util.Properties loadConfiguration(ServletConfig config) throwsjava.io.IOException, java.io.FileNotFoundException

{

return Utilities.initServletEnvironment(this);

}

}

2) ProcessSubPage.java , 比較簡(jiǎn)單,只定義了一個(gè)函數接口 getHtml

import javax.servlet.http.*;

import org.apache.velocity.context.*;

import org.apache.velocity.servlet.*;

import commontools.*;

public abstract class ProcessSubPage implements java.io.Serializable

{

public ProcessSubPage()

{

}

public String getHtml(VelocityServlet servlet, HttpServletRequest request,HttpServletResponse response,Context context)

{

Utilities.debugPrintln("you need to override this method in sub class of ProcessSubPage:"+ this.getClass().getName());

return "Sorry, this module not finish yet.";

}

}

他的 .java 文件基本上是 ProcessSubPage 的子類(lèi)和一些工具類(lèi)。 ProcessSubPage 的子類(lèi)基本上都是一樣的流程, 用類(lèi)似

context.put("page_footer",getPageFooterHTML());

的寫(xiě)法置換 .html 中的可變部分即可。如果沒(méi)有可變部分,完全是靜態(tài)網(wǎng)頁(yè),比如 AboutSubPage, 就更簡(jiǎn)單。

3) AboutSubPage.java

import org.apache.velocity.servlet.VelocityServlet;

import j

本站僅提供存儲服務(wù),所有內容均由用戶(hù)發(fā)布,如發(fā)現有害或侵權內容,請點(diǎn)擊舉報。
打開(kāi)APP,閱讀全文并永久保存 查看更多類(lèi)似文章
猜你喜歡
類(lèi)似文章
如何使用 velocity 模板引擎開(kāi)發(fā)網(wǎng)站
Velocity初體驗
CHAPTER 5 構建Hello World示例 - Velocity空間 - Blog...
Velocity java開(kāi)發(fā)指南
Velocity之Web實(shí)踐- - - 劉文濤 - BlogJava
Apache java項目全介紹
更多類(lèi)似文章 >>
生活服務(wù)
分享 收藏 導長(cháng)圖 關(guān)注 下載文章
綁定賬號成功
后續可登錄賬號暢享VIP特權!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服

欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久