利用xml xsl快速生成大量JSP的常用代码的方法.

2008-02-23 10:05:58来源:互联网 阅读 ()

新老客户大回馈,云服务器低至5折

利用XML xsl快速生成大量JSP的常用代码的方法.
参考JBuilder的Servlet向导来使用xml xsl产生JSP的常用代码。
xml样本:
<?xml version="1.0" encoding="GB2312"?>
<?xml-stylesheet type="text/xsl" href="jspram.xsl"?>
<jsp xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="jspsrcgen.xsd">
<param>
<variable>rloginusername</variable>
<name>loginusername</name>
<type>String</type>
<src>request</src>
<default>lizongbo</default>
<desc>用户的登录名</desc>
</param>
<param>
<variable>clastlogintime</variable>
<name>lastlogintime</name>
<type>long</type>
<src>cookie</src>
<default>0</default>
<desc>用户最近一次的登录时间</desc>
</param>
<param>
<variable>susERPass</variable>
<name>userpass</name>
<type>String</type>
<src>session</src>
<default>password</default>
<desc>存放在session里的密码</desc>
</param>
</jsp>
xsl文件略。
转换后的效果图和相关代码:

testjsp.jsp

变量名字参数名字变量类型变量来源默认值备注rloginusernameloginusernameStringrequestlizongbo用户的登录名rloginusernameloginusernameStringrequestlizongbo用户的登录名rloginusernameloginusernameStringrequestlizongbo用户的登录名suserpassuserpassStringsessionpassword存放在session里的密码suserpassuserpassStringsessionpassword存放在session里的密码suserpassuserpassStringsessionpassword存放在session里的密码clastlogintimelastlogintimelongcookie0用户最近一次的登录时间clastlogintimelastlogintimelongcookie0用户最近一次的登录时间clastlogintimelastlogintimelongcookie0用户最近一次的登录时间
生成好的Java代码:
<%@page import="com.lizongbo.util.JSPUtil"%>//用户的登录名String rloginusername = JSPUtil. getParameter(request,"loginusername",lizongbo); //用户的登录名String rloginusername = JSPUtil. getParameter(request,"loginusername",lizongbo); //用户的登录名String rloginusername = JSPUtil. getParameter(request,"loginusername",lizongbo); //存放在session里的密码String suserpass = JSPUtil.getAttribute(session,"userpass",password); //存放在session里的密码String suserpass = JSPUtil.getAttribute(session,"userpass",password); //存放在session里的密码String suserpass = JSPUtil.getAttribute(session,"userpass",password); //用户最近一次的登录时间long clastlogintime = JSPUtil. getValue(request.getCookies(),"lastlogintime",0); //用户最近一次的登录时间long clastlogintime = JSPUtil. getValue(request.getCookies(),"lastlogintime",0); //用户最近一次的登录时间long clastlogintime = JSPUtil. getValue(request.getCookies(),"lastlogintime",0);
我封装的JSPUtil代码片断:

public static string getparameter(httpservletrequest request, string name,
string defval) {
string param = request.getparameter(name);
return (param != null ? param : defval);
}

public static boolean getparameter(httpservletrequest request, string name,
boolean defval) {
string bv = request.getparameter(name);
return bv == null ? defval : parseboolean(bv);

}

public static double getparameter(httpservletrequest request, string name,
double defval) {
return parsedouble(request.getparameter(name), defval);
}

public static float getparameter(httpservletrequest request, string name,
float defval) {
return parsefloat(request.getparameter(name), defval);
}

public static int getparameter(httpservletrequest request, string name,
int defval) {
return parseint(request.getparameter(name), defval);
}

public static long getparameter(httpservletrequest request, string name,
long defval) {
return parselong(request.getparameter(name), defval);
}

public static short getparameter(httpservletrequest request, string name,
short defval) {
return parseshort(request.getparameter(name), defval);
}

上一篇: abstract class && Interface 比较

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:TIJ阅读笔记(第六章)

下一篇:从Hibernate2到3移植的两点初体验