|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
其实你不用Struts,spring这些工具,直接用jsp,servlet能够很方便地写出来,而且,可以根据个人的水平、爱好,有很多方案。而struts,spring这些工具的出来。js|客户端
请浏览以下代码。假如你的利用请求分歧,可对这些代码加以很便利的修正。这些代码可使你取得:
公司company,用户name,版本version,mainversion,minorversion
操纵体系(未完成!),言语language,locale等。
创建一个新的JSP文件:
请将以下class文件到场classpath(你要创建一样的目次布局--de.hunsicker.http.util,固然也能够本人调治包的称号。!):
packagede.hunsicker.http.util;
importjava.util.*;
importjavax.servlet.*;
importjavax.servlet.http.*;
publicclassBrowserextendsHttpServlet
{
protectedHttpServletRequestrequest;
protectedHttpSessionsession;
protectedStringuserAgent;
protectedStringcompany;//FirmennamedesHerstellers
protectedStringname;//BezeichnungdesBrowsers
protectedStringversion;//Version
protectedStringmainVersion;//Hauptversion
protectedStringminorVersion;//Unterversion
protectedStringos;//Betriebssystem
protectedStringlanguage="de";//SprachcodeStandard
protectedLocalelocale;//Locale-Objektmitdenaktuellen
//Spracheinstellungen
privateHashtablesupportedLanguages;//UntersttzteSprachen
publicBrowser(HttpServletRequestrequest,HttpSessionsession)
{
this.initialize();
this.request=request;
this.session=session;
this.setUserAgent(this.request.getHeader("User-Agent"));
this.setCompany();
this.setName();
this.setVersion();
this.setMainVersion();
this.setMinorVersion();
this.setOs();
this.setLanguage();
this.setLocale();
}
publicvoidinitialize()
{
this.supportedLanguages=newHashtable(2);
this.supportedLanguages.put("en","");
this.supportedLanguages.put("de","");
}
publicvoidsetUserAgent(StringhttpUserAgent)
{
this.userAgent=httpUserAgent.toLowerCase();
}
privatevoidsetCompany()
{
if(this.userAgent.indexOf("msie")>-1)
{
this.company="Microsoft";
}
elseif(this.userAgent.indexOf("opera")>-1)
{
this.company="OperaSoftware";
}
elseif(this.userAgent.indexOf("mozilla")>-1)
{
this.company="NetscapeCommunications";
}
else
{
this.company="unknown";
}
}
/**
*LiefertdenFirmennamendesHerstellersdesverwendetenBrowsers.
*/
publicStringgetCompany()
{
returnthis.company;
}
privatevoidsetName()
{
if(this.company=="Microsoft")
{
this.name="MicrosoftInternetExplorer";
}
elseif(this.company=="NetscapeCommunications")
{
this.name="NetscapeNavigator";
}
elseif(this.company=="Operasoftware")
{
this.name="OperasoftwareOpera";
}
else
{
this.name="unknown";
}
}
/**
*LiefertdenNamendesverwendetenBrowsers.
*/
publicStringgetName()
{
returnthis.name;
}
privatevoidsetVersion()
{
inttmpPos;
StringtmpString;
if(this.company=="Microsoft")
{
Stringstr=this.userAgent.substring(this.userAgent.indexOf("msie")+5);
this.version=str.substring(0,str.indexOf(";"));
}
else
{
tmpString=(this.userAgent.substring(tmpPos=(this.userAgent.indexOf("/"))+1,tmpPos+this.userAgent.indexOf(""))).trim();
this.version=tmpString.substring(0,tmpString.indexOf(""));
}
}
/**
*LiefertdieVersionsnummerdesverwendetenBrowsers.
*/
publicStringgetVersion()
{
returnthis.version;
}
privatevoidsetMainVersion()
{
this.mainVersion=this.version.substring(0,this.version.indexOf("."));
}
/**
*LiefertdieHauptversionsnummerdesverwendetenBrowsers.
*/
publicStringgetMainVersion()
{
returnthis.mainVersion;
}
privatevoidsetMinorVersion()
{
this.minorVersion=this.version.substring(this.version.indexOf(".")+1).trim();
}
/**
*LiefertdieUnterversionsnummerdesverwendetenBrowsers.
*/
publicStringgetMinorVersion()
{
returnthis.minorVersion;
}
privatevoidsetOs()
{
if(this.userAgent.indexOf("win")>-1)
{
if(this.userAgent.indexOf("windows95")>-1||this.userAgent.indexOf("win95")>-1)
{
this.os="Windows95";
}
if(this.userAgent.indexOf("windows98")>-1||this.userAgent.indexOf("win98")>-1)
{
this.os="Windows98";
}
if(this.userAgent.indexOf("windowsnt")>-1||this.userAgent.indexOf("winnt")>-1)
{
this.os="WindowsNT";
}
if(this.userAgent.indexOf("win16")>-1||this.userAgent.indexOf("windows3.")>-1)
{
this.os="Windows3.x";
}
}
}
/**
*LiefertdenNamendesBetriebssystems.
*/
publicStringgetOs()
{
returnthis.os;
}
privatevoidsetLanguage()
{
StringprefLanguage=this.request.getHeader("Accept-Language");
if(prefLanguage!=null)
{
Stringlanguage=null;
StringTokenizerst=newStringTokenizer(prefLanguage,",");
intelements=st.countTokens();
for(intidx=0;idxelements;idx++)
{
if(this.supportedLanguages.containsKey((language=st.nextToken())))
{
this.language=this.parseLocale(language);
}
}
}
}
/*
*HilfsfunktionfrsetLanguage().
*/
privateStringparseLocale(Stringlanguage)
{
StringTokenizerst=newStringTokenizer(language,"-");
if(st.countTokens()==2)
{
returnst.nextToken();
}
else
{
returnlanguage;
}
}
/**
*LiefertdasL?nderkürzeldervomBenutzer
*bevorzugtenSprache.
*/
publicStringgetLanguage()
{
returnthis.language;
}
privatevoidsetLocale()
{
this.locale=newLocale(this.language,"");
}
/**
*LieferteinLocale-ObjektmitderSprach-PrferenzdesverwendetenBrowsers
*/
publicLocalegetLocale()
{
returnthis.locale;
}
}
在性能方面,在windows平台下,.net可能是占强项,要是把.net放在sun开发的操作系统上去运行呢?根本就运行不了,.net对其它操作系统的支持也很弱,性能也可能比不上java。 |
|