当前位置导航:炫浪网>>网络学院>>网页制作>>JSP教程

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

利用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);  }
相关内容
赞助商链接