
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;">
??????????? <font color="#FF9900">■ </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 閱讀(473) |
評論 (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 閱讀(185) |
評論 (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">
?????? ??? <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 閱讀(1790) |
評論 (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 閱讀(272) |
評論 (0) |
編輯 收藏
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 閱讀(165) |
評論 (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 閱讀(650) |
評論 (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 閱讀(575) |
評論 (0) |
編輯 收藏