?? entryservlet.java
字號:
package mobi.javabeans.browserDetector.webSiteAction.entry;
import java.io.IOException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import mobi.javabeans.browserDetector.BrowserConstants;
import mobi.javabeans.browserDetector.DeviceConfig;
import mobi.javabeans.browserDetector.DeviceConfigDetector;
import mobi.javabeans.browserDetector.webSiteAction.MBD_Constants;
public class EntryServlet extends HttpServlet implements javax.servlet.Servlet {
private static final long serialVersionUID = 95431318845711574L;
private String web_entry_url = null;
private String wml_entry_url = null;
private String xmp_entry_url = null;
public EntryServlet() {
super();
}
public void init(ServletConfig config) throws ServletException {
web_entry_url = config.getInitParameter("web_entry_url");
wml_entry_url = config.getInitParameter("wml_entry_url");
xmp_entry_url = config.getInitParameter("xmp_entry_url");
}
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
gotoEntry(request, response);
}
protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
gotoEntry(request, response);
}
private void gotoEntry(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
DeviceConfig deviceConfig = DeviceConfigDetector
.detectCapabilities(request);
if (deviceConfig == null) {
deviceConfig = getDefaultMobileDeviceConfig();
}
request.getSession(true).setAttribute(
MBD_Constants.SESSIONKEY_DEVICE_CONFIG, deviceConfig);
RequestDispatcher dispacher = null;
if (web_entry_url == null)
throw new ServletException(
"The mandatory web_entry_url is not Specified!");
dispacher = request.getRequestDispatcher(web_entry_url);
if (deviceConfig.isMobileBrowser()) {
if (wml_entry_url == null && xmp_entry_url == null) {
throw new ServletException("No mobile site URL is Specified!");
}
if ((wml_entry_url != null) && (deviceConfig.isSupported_WML())) {
dispacher = request.getRequestDispatcher(web_entry_url);
} else if ((xmp_entry_url != null)) {
dispacher = request.getRequestDispatcher(xmp_entry_url);
}
}
dispacher.forward(request, response);
}
private DeviceConfig getDefaultMobileDeviceConfig() {
DeviceConfig mobileDeviceConfig = new DeviceConfig();
String[] languages = { "en" };
mobileDeviceConfig.setLanguages(languages);
mobileDeviceConfig.setBrowser(BrowserConstants.BROWSER_UP);
mobileDeviceConfig.setSupported_XHTMLMP(true);
mobileDeviceConfig.setSupported_GIF(true);
mobileDeviceConfig.setSupported_WBMP(false);
mobileDeviceConfig.setSupported_XHTML(false);
mobileDeviceConfig.setSupported_HTML(false);
return mobileDeviceConfig;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -