posts - 9,  comments - 1,  trackbacks - 0
  2006年9月21日
<SCRIPT language=javascript1.2>
function showsubmenu(sid)
{
whichEl = eval("submenu" + sid);
if (whichEl.style.display == "none")
{
eval("submenu" + sid + ".style.display=\"\";");
}
else
{
eval("submenu" + sid + ".style.display=\"none\";");
}
}
</SCRIPT>


用法:

<tr>
            <td height="26" background="../image/menu.gif" id="menuTitle1" onClick="showsubmenu(1)" style="cursor:hand;">&nbsp;&nbsp;&nbsp;
            <font color="#FF9900">■&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#FFFFFF"><strong>知识库分类</strong></font>
            </td>
          </tr>
          <tr>
<td style="display:none" id='submenu1'>
     <table cellspacing="0" align="center" width="100%">
                <tr>
                  <td class="nav">· <a href="<%=request.getContextPath()%>/knowledge/knowledgeCategoryList.htm?order=list" target="mainFrame">编辑知识库分类</a></td>
                </tr>
                <tr>
                  <td class="nav">· <a href="<%=request.getContextPath()%>/knowledge/knowledgeCategoryList.htm?order=edit" target="mainFrame">新增知识库分类</a></td>
                </tr>
              </table>
posted @ 2006-10-25 17:37 lovetq 阅读(460) | 评论 (0)编辑 收藏
在很多的列表中,后面的操作一栏会有删除链接,并且会让你确认。此处的代码: 
<a href='javascript:deleteCategory("<%=article.getId() %>")'>删除</a>
     

javascript函数
<script>
 function deleteCategory(articleId)
 {
  if(confirm('是否真的要删除该记录'))
   window.location='<%=request.getContextPath()%>/info/infoArticleEdit.htm?order=delete&articleId='+articleId;
 }
</script>

一些链接:
<input class="button3" type=button value="返回" onclick="javascript:window.location='<%=request.getContextPath() %>/info/infoArticleList.htm'">

<td>文件名:<a href='<%=request.getContextPath()%>/info/infoArticleEdit.htm?order=download&fileId=<%=accessory.getId() %>'><%=accessory.getFileExt() %></a>
     
<c:url value="........" />
  
一些传值
<input type=hidden name=order value=save>
<input type=hidden name=id value="<c:out value="${infoArticle.id}" />">
<input type=hidden name=navId value="<%=request.getParameter("navId") %>">
<input type=hidden name=fileCount value=1>
posted @ 2006-10-25 16:32 lovetq 阅读(174) | 评论 (0)编辑 收藏

页面代码:
<!--  这个是显示的多选框页面 已有的角色要打勾,可以重新选择角色-->
<form action="<c:url value="/sys/userRolesEdit.htm"/>" method="post" >

      <table class="grid" width="100%" cellspacing="1">
     
    <tr>
       <td colspan="6" class="title">
          角色列表
       </td>
    </tr>
    <tr>
      <td class="column"></td>
       <td class="column">角色ID</td>
       <td class="column">角色名</td>
       <td class="column">角色代码</td>
       <td class="column">角色描述</td>      

    </tr>

    <!-- 循环显示列表userRoles的每一项,并判断如果数据库中已有的打勾<c:if test标签正确才执行中间的代码-->
    <c:forEach items="${roles}" var="item">    
   <tr>      
     <td>
     <input type="checkbox" name="rolesId" <c:forEach items="${userRoles}" var = "selectedRoles">
     <c:if test="${item.srolId == selectedRoles.srolId}">checked="true"</c:if></c:forEach>
      value="<c:out value="${item.srolId}"/>" />
     </td>
   
     <td><c:out value="${item.srolId}"/></td>
        <td><c:out value="${item.srolName}"/> </td>
                 <td><c:out value="${item.srolCode}"/></td>
                 <td><c:out value="${item.srolDesc}"/></td>                
     <tr>       
    </c:forEach>   
   
    <tr>

       <td colspan="6" class="nav">&nbsp;
           <input type="hidden" name="userID"
   value=<c:out value="${userInfo.suinId}"/>>
      <input type="submit" class="button3" value="提交"/>
      <INPUT type="button" class="button2" value="返回" onclick="history.back()" />
     
       </td>
    </tr>
   </table> 
   </form>

控制器代码:
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
  // TODO Auto-generated method stub
  
  Map result = new HashMap();
  
  SysUserinfo userInfo = null;
        String id = request.getParameter("userID");

        System.out.println(id);
        if (id != null && !id.equals(""))
        {
            userInfo = (SysUserinfo) sysService.get(SysUserinfo.class,
                    new Long(id));
           
        }
        else
        {
           
        }
       
        result.put("userInfo", userInfo);
        result.put("roles", sysService.getSupportData("SysRole", null));
        if (userInfo != null)
        {
         result.put("userRoles", sysService.getUserRoles(userInfo));
        }
       
 
       
        SysUserRole sysUserRole = null;
        SysRole sysRole = null;
        String roleId = null;
       
        // 记录父列表ID
        result.put("parentlistID", request.getParameter("parentlistID"));
        result.put("userInfo", userInfo);
        
         //遍历所有map里的key
        Iterator it = result.keySet().iterator();
        while (it.hasNext())
        {
            String key = (String) it.next();
            request.setAttribute(key, result.get(key));
        }
        
         //这里就是从列表多选框传过来的数值。根据name属性获得所有的value
        String[] rolesId = null;
        rolesId = request.getParameterValues("rolesId");
        System.out.println("------------------------" + rolesId + "-------------------");
       
        if (rolesId == null || rolesId.equals(null))
        {
         return new ModelAndView(formView);
        }
       
        else
        {     
         List userRoles = (List)sysService
          .getUsersUserRoles(userInfo.getSuinId());


      //先删除数据库中所有的,再插入所选的值
         for (int k = 0; k < userRoles.size(); k++)
      {
       SysUserRole userRole = (SysUserRole)userRoles.get(k);      
       sysService.delete(userRole);
       
      }
         
         for (int i = 0; i < rolesId.length; i++)
         {
          roleId = rolesId[i];
          
          sysRole = (SysRole)sysService.get(SysRole.class, new Long(roleId));
          sysUserRole = new SysUserRole();
          sysUserRole.setUser(userInfo);
          sysUserRole.setRole(sysRole);
          sysService.save(sysUserRole);        
         }

         //如果在###-servlet.xml配置文件中,successView不能传递参数,可在这里直接有response导向别的页面
         response.sendRedirect(request.getContextPath()
           + "/sys/userRolesList.htm?userID=" + userInfo.getSuinId().toString());
         return null;
        }

 }


posted @ 2006-10-25 09:27 lovetq 阅读(1777) | 评论 (0)编辑 收藏
StringTokenizer:字符串分隔解析类型
属于:java.util包。

1、构造函数。

    1. StringTokenizer(String str) :构造一个用来解析str的StringTokenizer对象。java默认的分隔符是“空格”、“制表符(‘\t’)”、“换行符(‘\n’)”、“回车符(‘\r’)”。
    2. StringTokenizer(String str, String delim) :构造一个用来解析str的StringTokenizer对象,并提供一个指定的分隔符。
    3. StringTokenizer(String str, String delim, boolean returnDelims) :构造一个用来解析str的StringTokenizer对象,并提供一个指定的分隔符,同时,指定是否返回分隔符。


2、方法。
说明:
1. 所有方法均为public;
2. 书写格式:[修饰符] <返回类型> <方法名([参数列表])>

如:
static int parseInt(String s) 表示:此方法(parseInt)为类方法(static),返回类型为(int),方法所需参数为String类型。


    1. int countTokens() :返回nextToken方法被调用的次数。如果采用构造函数1和2,返回的就是分隔符数量(例2)。
    2. boolean hasMoreTokens() :返回是否还有分隔符。
    3. boolean hasMoreElements() :结果同2。
    4. String nextToken() :返回从当前位置到下一个分隔符的字符串。
    5. Object nextElement() :结果同4。
    6. String nextToken(String delim) :与4类似,以指定的分隔符返回结果。


例子:
		String s = new String("The Java platform is the ideal platform for network computing");
StringTokenizer st = new StringTokenizer(s);
System.out.println( "Token Total: " + st.countTokens() );
while( st.hasMoreElements() ){
System.out.println( st.nextToken() );
           }
结果为:
Token Total: 10
The
Java
platform
is
the
ideal
platform
for
network
computing

例2:
		String s = new String("The=Java=platform=is=the=ideal=platform=for=network=computing");
StringTokenizer st = new StringTokenizer(s,"=",true);
System.out.println( "Token Total: " + st.countTokens() );
while( st.hasMoreElements() ){
System.out.println( st.nextToken() );
}
结果为:
Token Total: 19
The
=
Java
=
platform
=
is
=
the
=
ideal
=
platform
=
for
=
network
=
computing
posted @ 2006-10-08 17:33 lovetq 阅读(260) | 评论 (0)编辑 收藏
jsp
JSP语法(9)——jsp:getProperty

<jsp:getProperty>

获取Bean的属性值,用于显示在页面中

JSP 语法

<jsp:getProperty name="beanInstanceName" property="propertyName" />

例子

<jsp:useBean id="calendar" scope="page" class="employee.Calendar" />

<h2>

Calendar of <jsp:getProperty name="calendar" property="username" />

</h2>

描述

这个<jsp:getProperty>元素将获得Bean的属性值,并可以将其使用或显示在JSP页面中.在你使用<jsp:getProperty>之前,你必须用<jsp:useBean>创建它.

<jsp:getProperty>元素有一些限制:

你不能使用<jsp:getProperty>来检索一个已经被索引了的属性

你能够和JavaBeans组件一起使用<jsp:getProperty>,但是不能与Enterprise

Bean一起使用。

属性

name="beanInstanceName"
bean的名字,由<jsp:useBean>指定

property="propertyName"
所指定的Bean的属性名。

技巧:

在sun的JSP参考中提到,如果你使用<jsp:getProperty>来检索的值是空值,那么NullPointerException将会出现,同时如果使用程序段或表达式来检索其值,那么在浏览器上出现的是null(空).



jsp:getProperty Action

语法:

  <jsp:getProperty name="beanInstanceName" property="propertyName" />

  这个属性检索出bean的属性的值并将之转化为一个字符串,然后将之插入到输出。它有两个必选属性:name,在之前用jsp:useBean引入的名称,property,必须被插入值的属性。

posted @ 2006-09-21 13:46 lovetq 阅读(151) | 评论 (0)编辑 收藏

java.util.*;

public class ShowDate {

public static void main(String[] args) {
Calendar calendar = new GregorianCalendar();
Date trialTime = new Date();
calendar.setTime(trialTime);

// print out a bunch of interesting things
System.out.println("ERA: " + calendar.get(Calendar.ERA));
System.out.println("YEAR: " + calendar.get(Calendar.YEAR));
System.out.println("MONTH: " + calendar.get(Calendar.MONTH));
System.out.println("WEEK_OF_YEAR: " + calendar.get(Calendar.WEEK_OF_YEAR));
System.out.println("WEEK_OF_MONTH: " + calendar.get(Calendar.WEEK_OF_MONTH));
System.out.println("DATE: " + calendar.get(Calendar.DATE));
System.out.println("DAY_OF_MONTH: " + calendar.get(Calendar.DAY_OF_MONTH));
System.out.println("DAY_OF_YEAR: " + calendar.get(Calendar.DAY_OF_YEAR));
System.out.println("DAY_OF_WEEK: " + calendar.get(Calendar.DAY_OF_WEEK));
System.out.println("DAY_OF_WEEK_IN_MONTH: " + calendar.get(Calendar.DAY_OF_WEEK_IN_MONTH));
System.out.println("AM_PM: " + calendar.get(Calendar.AM_PM));
System.out.println("HOUR: " + calendar.get(Calendar.HOUR));
System.out.println("HOUR_OF_DAY: " + calendar.get(Calendar.HOUR_OF_DAY));
System.out.println("MINUTE: " + calendar.get(Calendar.MINUTE));
System.out.println("SECOND: " + calendar.get(Calendar.SECOND));
System.out.println("MILLISECOND: " + calendar.get(Calendar.MILLISECOND));
System.out.println("ZONE_OFFSET: " + (calendar.get(Calendar.ZONE_OFFSET)/(60*60*1000)));
System.out.println("DST_OFFSET: " + (calendar.get(Calendar.DST_OFFSET)/(60*60*1000)));

System.out.println("Current Time, with hour reset to 3");
calendar.clear(Calendar.HOUR_OF_DAY); // so doesn't override
calendar.set(Calendar.HOUR, 3);
System.out.println("ERA: " + calendar.get(Calendar.ERA));
System.out.println("YEAR: " + calendar.get(Calendar.YEAR));
System.out.println("MONTH: " + calendar.get(Calendar.MONTH));
System.out.println("WEEK_OF_YEAR: " + calendar.get(Calendar.WEEK_OF_YEAR));
System.out.println("WEEK_OF_MONTH: " + calendar.get(Calendar.WEEK_OF_MONTH));
System.out.println("DATE: " + calendar.get(Calendar.DATE));
System.out.println("DAY_OF_MONTH: " + calendar.get(Calendar.DAY_OF_MONTH));
System.out.println("DAY_OF_YEAR: " + calendar.get(Calendar.DAY_OF_YEAR));
System.out.println("DAY_OF_WEEK: " + calendar.get(Calendar.DAY_OF_WEEK));
System.out.println("DAY_OF_WEEK_IN_MONTH: " + calendar.get(Calendar.DAY_OF_WEEK_IN_MONTH));
System.out.println("AM_PM: " + calendar.get(Calendar.AM_PM));
System.out.println("HOUR: " + calendar.get(Calendar.HOUR));
System.out.println("HOUR_OF_DAY: " + calendar.get(Calendar.HOUR_OF_DAY));
System.out.println("MINUTE: " + calendar.get(Calendar.MINUTE));
System.out.println("SECOND: " + calendar.get(Calendar.SECOND));
System.out.println("MILLISECOND: " + calendar.get(Calendar.MILLISECOND));
System.out.println("ZONE_OFFSET: " + (calendar.get(Calendar.ZONE_OFFSET)/(60*60*1000))); // in hours
System.out.println("DST_OFFSET: " + (calendar.get(Calendar.DST_OFFSET)/(60*60*1000))); // in hours
}

}


import java.text.DateFormat;
import java.util.*;

public class JspCalendar {
    Calendar  calendar = null;

    public JspCalendar() {
 calendar = Calendar.getInstance();
 Date trialTime = new Date();
 calendar.setTime(trialTime);
    }

    public int getYear() {
 return calendar.get(Calendar.YEAR);
    }
   
    public String getMonth() {
 int m = getMonthInt();
 String[] months = new String [] { "January", "February", "March",
     "April", "May", "June",
     "July", "August", "September",
     "October", "November", "December" };
 if (m > 12)
     return "Unknown to Man";
 
 return months[m - 1];

    }

    public String getDay() {
 int x = getDayOfWeek();
 String[] days = new String[] {"Sunday", "Monday", "Tuesday", "Wednesday",
          "Thursday", "Friday", "Saturday"};

 if (x > 7)
     return "Unknown to Man";

 return days[x - 1];

    }
   
    public int getMonthInt() {
 return 1 + calendar.get(Calendar.MONTH);
    }

    public String getDate() {
 return getMonthInt() + "/" + getDayOfMonth() + "/" +  getYear();

    }

    public String getTime() {
 return getHour() + ":" + getMinute() + ":" + getSecond();
    }

    public int getDayOfMonth() {
 return calendar.get(Calendar.DAY_OF_MONTH);
    }

    public int getDayOfYear() {
 return calendar.get(Calendar.DAY_OF_YEAR);
    }

    public int getWeekOfYear() {
 return calendar.get(Calendar.WEEK_OF_YEAR);
    }

    public int getWeekOfMonth() {
 return calendar.get(Calendar.WEEK_OF_MONTH);
    }

    public int getDayOfWeek() {
 return calendar.get(Calendar.DAY_OF_WEEK);
    }
    
    public int getHour() {
 return calendar.get(Calendar.HOUR_OF_DAY);
    }
   
    public int getMinute() {
 return calendar.get(Calendar.MINUTE);
    }


    public int getSecond() {
 return calendar.get(Calendar.SECOND);
    }

    public static void main(String args[]) {
 JspCalendar db = new JspCalendar();
 p("date: " + db.getDayOfMonth());
 p("year: " + db.getYear());
 p("month: " + db.getMonth());
 p("time: " + db.getTime());
 p("date: " + db.getDate());
 p("Day: " + db.getDay());
 p("DayOfYear: " + db.getDayOfYear());
 p("WeekOfYear: " + db.getWeekOfYear());
 p("era: " + db.getEra());
 p("ampm: " + db.getAMPM());
 p("DST: " + db.getDSTOffset());
 p("ZONE Offset: " + db.getZoneOffset());
 p("TIMEZONE: " + db.getUSTimeZone());
    }

    private static void p(String x) {
 System.out.println(x);
    }


    public int getEra() {
 return calendar.get(Calendar.ERA);
    }

    public String getUSTimeZone() {
 String[] zones = new String[] {"Hawaii", "Alaskan", "Pacific",
           "Mountain", "Central", "Eastern"};
 
 return zones[10 + getZoneOffset()];
    }

    public int getZoneOffset() {
 return calendar.get(Calendar.ZONE_OFFSET)/(60*60*1000);
    }


    public int getDSTOffset() {
 return calendar.get(Calendar.DST_OFFSET)/(60*60*1000);
    }

   
    public int getAMPM() {
 return calendar.get(Calendar.AM_PM);
    }
}

posted @ 2006-09-21 11:45 lovetq 阅读(636) | 评论 (0)编辑 收藏
<jsp:useBean id=“calculator“ scope=“request“ class=“com.jspdev.SimpleCalculator“>
<jsp:setProperty name=“calculator“ property=“*“/>
</jsp:useBean>

(1)property=”*”
设置Bean 属性的快捷方式,在Bean 中属性的名字,类型必须和request对象中的参数名称相匹配。由于表单中传过来的数据类型都是String 类型的,Jsp内在机制会把这些参数转化成Bean属性对应的类型。
(2)property=“propertyName“
使用request对象中的一个参数值来指定Bean中的一个属性值。在这个语法中,property指定Bean 的属性名,而且Bean 属性和request参数的名字应相同。也就是说,如果在Bean 中有setUserName(String userName)方法,那么,propertyName的值就是“userName“

<jsp:setProperty name="Name" property="*" />
根据已提交表单中的数据,设置这个javaBean中相应的属性值。
*:JavaBean属性的名称和表单对象的名称相同时才能够赋值
<jsp:setProperty name="Name" property="propertyName" value="PropertyValue" | param="ParameterName" />
把JavaBean指定的属性设为指定的值

jsp:setProperty用来设置Bean的属性值。
有两种方法使用
1。在jsp:useBean之后2。在jsp:useBean实体这中间有区别的第一种情况jsp:setProperty
不管是新生成的实例还是原来的对象,都会进行
2。只有在新生成的情况下才可以执行
<jsp:setProperty>中的name 应该和jsp:useBean中的id一样的
property="*" 表示用用户输入的所有值来匹配Bean中的属性,当然你也可以指定的

posted @ 2006-09-21 11:34 lovetq 阅读(564) | 评论 (0)编辑 收藏