Explore Enterprise Education Gitee Premium Gitee AI AI teammates
Fetch the repository succeeded.
forked from 老馬/WebJava
Create your Gitee Account
Explore and code with more than 14 million developers,Free private repositories !:)
Sign up
Already have an account? Sign in
文件
master
Branches (1)
master
This repository doesn't specify license. Please pay attention to the specific project description and its upstream code dependency when using it.
The license selected for the repository is subject to the license used by the main branch of the repository.
master
Branches (1)
master
Clone or Download
Clone/Download
Prompt
To download the code, please copy the following command and execute it in the terminal
To ensure that your submitted code identity is correctly recognized by Gitee, please execute the following command.
When using the SSH protocol for the first time to clone or push code, follow the prompts below to complete the SSH configuration.
1 Generate RSA keys.
2 Obtain the content of the RSA public key and configure it in SSH Public Keys
To use SVN on Gitee, please visit the usage guide
When using the HTTPS protocol, the command line will prompt for account and password verification as follows. For security reasons, Gitee recommends configure and use personal access tokens instead of login passwords for cloning, pushing, and other operations.
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # Private Token
master
Branches (1)
master
WebJava
/
Web
/
Handler.java
WebJava
/
Web
/
Handler.java
Handler.java 4.33 KB
Copy Edit Raw Blame History
Ma authored 2015年06月12日 09:41 +08:00 . 添加Demo
package Web;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.HashMap;
/**
*
* @author Ma
*/
public class Handler {
public Request request;
/**
* 初始化Handler
*/
public void init(Request request) {
this.request = request;
}
/**
* 用于实现一些类似构造方法的作用
* @todo 装饰器实现
*/
public void construct() {
;
}
/**
* 获取参数
* @param key
* @return
*/
public Object getArgument(String key){
return this.request.Arguments.get(key);
}
/**
* 把模版或者字符串写入
* @param s
*/
public void writer(String s) {
Response.setContent(s);
}
/**
* 读取模版
*/
public BaseTemplate render(String fileName) {
try {
BaseTemplate object;
if (Options.DEBUG) {
fileName = fileName.replace(".", "/");//把点替换成路径
TplCompile tplCompile = new TplCompile();
object = (BaseTemplate) tplCompile.run(fileName + ".html");
if (object == null) {
InternalServerError500.set500(fileName + "模版不存在!");
}
} else {
Class TemplateClass = Class.forName("Template." + fileName + "Template");
object = (BaseTemplate) TemplateClass.newInstance();
}
return object;
} catch (ClassNotFoundException ex) {
//模版不存在
InternalServerError500.set500(fileName + "模版不存在!");
Logger.getLogger(Handler.class.getName()).log(Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
Logger.getLogger(Handler.class.getName()).log(Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
Logger.getLogger(Handler.class.getName()).log(Level.SEVERE, null, ex);
}
return null;
}
/**
* 重定向到URL,发送303
*
* @param url
*/
public void redirect(String url) {
Response.setStatus(303);
if (url.toLowerCase().indexOf("http://") < 0) {
url = "http://" + this.request.Header.get("Host") + url;
}
Response.header("Location: " + url);
}
/**
* 页面跳转到URL中,通过HTML
*
* @param url
* @param time
*/
public void jump(String message, String url, int time, boolean status) {
boolean isSetUrl = false;
if (message == null) {
message = "Message!";
}
if (time < 1) {
time = 3;
}
if ("XMLHttpRequest".equals(this.request.Header.get("X-Requested-With"))) {
//判断Ajax请求
HashMap map = new HashMap();
map.put("static", status);
map.put("data", message);
Response.setContentType(Response.findContentType("json"));
this.writer(Json.encode(map));
} else {
BaseTemplate jump = this.render("jump");
jump.assign("status", status);
jump.assign("message", message);
if (url != null) {
isSetUrl = true;
}
jump.assign("isSetUrl", isSetUrl);
jump.assign("url", url);
jump.assign("wait", time);
this.writer(jump.display());
}
}
/**
* 操作成功
*/
public void success(String message, String url, int time) {
if (message == null) {
message = "Success!";
}
this.jump(message, url, time, true);
}
/**
* 操作成功
*/
public void success(String message, String url) {
this.success(message, url, 0);
}
/**
* 操作成功
*/
public void success(String message) {
this.success(message, null, 0);
}
/**
* 操作错误
*/
public void error(String message, String url, int time) {
if (message == null) {
message = "Error!";
}
this.jump(message, url, time, false);
}
/**
* 操作错误
*/
public void error(String message, String url) {
this.error(message, url, 0);
}
/**
* 操作错误
*/
public void error(String message) {
this.error(message, null, 0);
}
}
Loading...
Report
Report success
We will send you the feedback within 2 working days through the letter!
Please fill in the reason for the report carefully. Provide as detailed a description as possible.
Please select a report type
Cancel
Send
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

About

Web.Java是一个高性能的Java服务器。
Cancel

Releases

No release

Contributors

All

Activities

can not load any more
Edit
About
Homepage
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/xintao/WebJava.git
git@gitee.com:xintao/WebJava.git
xintao
WebJava
WebJava
master
Going to Help Center

Search

Comment
Repository Report
Back to the top
Login prompt
This operation requires login to the code cloud account. Please log in before operating.
Go to login
No account. Register

AltStyle によって変換されたページ (->オリジナル) /