前兩天初步認識了一下struts2
今兒看來教程的第二三講,搞清了一些前面的一些猜測或是疑問
1、struts2是不用<html:...>標簽了,統一成了<s:...>
如下這樣:
<s:form action="Converter">
<s:textfield name="point" label="Point"></s:textfield>
<s:submit label="submit"></s:submit>
</s:form>
顯示效果:

注意到<s:textfield name="point" label="Point"></s:textfield>
中的label屬性,它指定了文本框前面顯示的內容,還自動加了冒號,哈哈,挺聰明的嘛,但是擔心這樣在復雜的頁面設計中是不是好使。
哦對了,要想這么寫,要在頁面上方加上這個:<%@ taglib prefix="s" uri="/struts-tags" %>
2、Action
前面說的Action不再需要繼承任何struts類,現在看來要失望了,為了方便起見還是建議集成ActionSupport類,目前覺得有用的是ActionSupport中定義了幾個static的result name,比如SUCCESS、ERROR,原來的return "success";現在可以寫成return super.SUCCESS;,將標識用的字符串常量定義成static的是一直提倡的,還有就是validate()方法,驗證有錯誤可以調用addFieldError()方法,好像就是struts1 ActionForm里的東西,有所改進的是super.addFieldError("username", "username is null");將在頁面中顯示的效果為:錯誤信息"username is null"將在名字為"username"文本框的上面顯示,這些如果能用ajax實現就好了。
對于Action解耦,可能在于它不再需要HttpServletRequest 、HttpServletResponse這樣的容器運行時參數吧
Powered by Zoundry Raven
今天第一次感覺到經濟危機在我身邊了,部門現在沒有在做的項目了
經濟危機中,趕緊為自己充充電,好到時候柳暗花明又一村,哈哈
學struts2
據說struts2基于webwork,基本上跟struts1沒啥關系,如果有webwork的經驗上手會很迅速
我沒接觸過webwork,就知道有這么個東西
今兒開始第一個struts
見過好多blog寫有struts2的入門步驟,俺也寫一個,為自己造個輪子,加深印象。
首先下載struts2的jar包,到http://struts.apache.org/,右上角有個struts2的鏈接,今天下到的是
struts2的2.0.14,昨天在javaeye上看到發布
Struts2.1.3
發布了,只是主頁還沒看到,不止一次聽大拿們說過不要追求新版本,哈哈
下載后的目錄:app--struts的例子
docs-doc文檔
lib-struts的jar包或依賴包
src-源碼
HelloWorld:
1、index.jsp
耳目一新的是,不需要用到struts html標簽,這只是猜測,或許例子過于簡單?今天工作中還感覺struts1的html標簽真是不好用,想加個class、maxlength、size都不好使,讓我很是郁悶。希望在繼續學習中真的能耳目一新。
struts的action慣例后綴名改成了.action,不再像struts1的.do了,說是延續到webwork的慣例。
下面的頁面代碼submit的時候將提交到login.action
index.jsp
<body>
<form action="login.action" method="post">
username:
<input type="text" name="username"/>
password:
<input type="password" name="password"/>
<input type="submit" value="submit"/>
</form>
</body>
2、Action類
struts2的Action可是大進步,不用再繼承任何類,實現了松耦合,它好像將struts1的ActionForm融合了進來,據說struts2不再用ActionForm,頁面上對應的字段寫在了Action中,struts2框架會自動調用get/set方法,在我印象里struts1中的Action對象不是線程安全的,會在不同線程間重用,所以謹慎在里面定義字段,在這看來struts2的Action不是這樣的,只是猜測
package com.mystart.action;
public class LoginAction {
private String
username;
private String
password;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.
username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.
password = password;
}
public String execute()
throws Exception{
return "success";
}
}
3、jsp、java類都定義了,現在要它們聯系起來-struts配置文件
新的struts配置文件有個package包的概念,還沒鬧明白這個package的詳細用法,有待繼續深入
<action>標簽有變化,type變成了class,path變成了name,struts1中name屬性是制定ActionForm的,現在ActionForm沒有了
forward變成了result,result的默認name=success
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="struts" extends="struts-default">
<action name="login" class="com.mystart.action.LoginAction">
<result name="success">/result.jsp
</result>
</action>
</package>
</struts>
4、最后啟動struts2,配置web.xml
struts1的web.xml配置是放在<servlet>中,也就是是一個servlet
struts2變成了一個過濾器Filter
struts1中<url-pattern>被配置成攔截.do的鏈接
struts2變成了攔截所有鏈接 /*
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<filter>
<filter-name>struts2
</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher
</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2
</filter-name>
<url-pattern>/*
</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>index.jsp
</welcome-file>
</welcome-file-list>
</web-app>
以上是驢了個struts的視頻教程,今兒看了第一節課,看完后做了一下總結,里面有一些自己的理解,有不對的地方請兄弟們指正,別光光說我是豬,豬也要進步啊,嘿嘿,每一步都有疑問,明天帶著問題接著看下一節,睡覺去。
自定義Annotation
早就知道jdk5加了新特性Annotation,但是沒研究過,前幾天公司培訓,有一部分是介紹jdk5新特性的,一個是注解一個泛型
今兒復習一下注解
//用@Deprecated聲明該方法不建議使用
@Deprecated public void doSomething1(){
Map map = new HashMap();
map.put("some", "thing");
System.out.println(map);
}
//用@SuppressWarnings聲明不再進行類型檢查
@SuppressWarnings(value={"unchecked"})
public void doSomething2(){
Map map = new HashMap();
map.put("some", "thing");
}
寫一個自定義注解先
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
//要在運行時使用這個注解,必須聲明成RUNTIME
Annotation分為三種級別:RUNTIME、CLASS、SOURCE
@Retention(RetentionPolicy.
RUNTIME)
public @interface SomeAnnotation{
String value();
String name();
}
下面來使用這個自定義注解:
import java.lang.reflect.Method;
public class AnnotationTest {
@SomeAnnotation(value=
"value1",name=
"name1")
public void doSomething3(){
}
public static void main(String[] args){
Class<AnnotationTest> c = AnnotationTest.
class;
try {
//利用反射得到方法doSomething3
Method method = c.
getMethod(
"doSomething3");
//查找doSomething3方法是否有SomeAnnotation的Annotation
if(method.
isAnnotationPresent(SomeAnnotation.
class)){
System.
out.
println(
"找到SomeAnnotation");
//得到SomeAnnotation
SomeAnnotation annotation = method.
getAnnotation(SomeAnnotation.
class);
System.
out.
println(
"annotation.value="+annotation.
value());
System.
out.
println(
"annotation.name="+annotation.
name());
}
else{
System.
out.
println(
"沒有找到omeAnnotation");
}
}
catch (SecurityException e) {
e.
printStackTrace();
}
catch (NoSuchMethodException e) {
e.
printStackTrace();
}
}
}
輸出結果:
找到SomeAnnotation
annotation.value=value1
annotation.name=name1
遇到一個郁悶的問題 ,百思不得其解
到這里請大家分析分析
outtable 表中有四條記錄 如下圖
我按out_scrpno排序,為什么2008-1000不在第一行呢???
同樣的問題,如下圖
為什么會是2008-999呢 為啥不是2008-1000???
請大家幫忙是啥子原因,多謝,多謝
Powered by Zoundry Raven
ps:問題基本解決,感謝各位提示:
SELECT TOP 1 OUT_SCRPNO FROM OUTTABLE WHERE CHARINDEX('-',OUT_SCRPNO,6) = 0 ORDER BY CONVERT(int,REPLACE(out_scrpno,'-','')) DESC
另好像不該發到首頁,請管理員包含,心切
因為要修改一個以前的老項目,老項目用的jdk是1.4版本,遂在項目右鍵Properties-Java Compiler中將Compiler compliance level 設成了1.4

以為萬事大吉了呢,昨晚上因為Integer的一個方法發現了問題
Integer中有個方法valueOf
其中valueOf(int i)
- 從以下版本開始:
- 1.5
也就是在1.5之前沒有這個方法,但是在eclipse中卻有這個方法的提示

找了半天,原來問題出在這,在Java Build Path 中Libraries 中jdk是1.5的,把它remove掉,添加一個1.4的就OK了

還是功力不夠啊 充電 充電ing
下了個Hibernate視頻教程聽,雖然一年多以前跟老師學過Hibernate,但現在聽聽還是有很多收獲的,發現自己的知識知道的都是些皮毛,用了很久的東西,知道怎么操作怎么用,但要說說它的所以然,搖搖頭,呵呵
根據主鍵Id得到一個持久對象,Hibernate中有兩個方法,一個get,一個load,他們兩個參數相同,都返回一個Object
它們的區別:
執行get方法即時生成查詢sql去查詢數據庫得到相應的pojo,如果數據庫中沒有相應記錄,則返回null
執行load方法不會即時產生sql語句,而是在用到返回的對象時采取查詢數據庫,也就是load方法有默認的延遲加載,在執行load方法后返回的不是一個pojo對象,是pojo對象的一個代理(據說Hibernate是用代理的方式實現延遲加載的,這塊還迷糊),如果數據庫中沒有相應記錄,load方法會拋出異常ObjectNotFoundException
看了一下我們用MyEclipse hibernate工具通過數據庫生成的DAO類,它的findById方法是用的session.get()方法,這是即時獲得pojo對象,如果是load方法,在執行完load后如果關閉了session,那在接下來用到這個pojo對象時恐怕會報session已關閉的錯誤。
還有就是這兩個方法的第二個參數id,它必須是實現了java.io.Serializable接口,也就是可序列化的。
今天好像是立冬,冬天到了,抓緊時間充充電,明天接著學...
學習Linux,裝了個VMware,在上面裝了個紅帽4
前輩建議用host-only連接方式,好處是與host建立一個私有的網絡,跟外界沒有關系,A private network shared with the host
在這種方式下Linux如何上網呢
1、首先,安裝VMware后windows下會多出兩塊虛擬網卡,VMware Network Adapter VMnet1(為host-only方式用)和VMware Network Adapter VMnet8(為NAT方式用),將這兩塊網卡的IP都設為自動獲取。
2、將window上自己的網卡設為共享

3、進入Linux,應用程序-系統設置-網絡
選中eth0,點編輯,做如下配置

完成后點確定,然后點擊激活,OK,打開firefox試試看
下了個Linux的視頻教程
學了幾個命令記錄下來
其中對于Linux名字的解釋挺有意思,Linux is not unix,:-D
Linux中認為所有的硬件,所有的設備都是文件,文件分為字符文件,和塊設備(就是二進制的),它將所有的設備都放在dev目錄中
cd / 訪問根目錄
ls 顯示目錄中的文件列表
cd dev 訪問dev目錄
mkdir my 創建目錄my
rmdir my 刪除目錄my
mount /dev/cdrom /mnt/my 將cdrom掛載到my目錄
nmount /dev/cdrom 解除掛載
whoami 顯示當前用戶
pwd 顯示當前所在目錄
摘要: 原文:http://bbs.80nian.net/thread-428-1-1.html
百度的popup.js這個文件中的彈出層方法挺好用的,但是,有些時候,發現在Mozilla Firefox瀏覽器下彈出層不能正常使用,具體表現為:層不能移動,一起停在頁面左下角,遮罩層不能完全遮罩頁面。
解決方案:刪除被調用頁面中的“<!DOCTY...
閱讀全文
//將給定日期增加NumDay個月
function addDate(dtDate,NumDay){
var date = new Date(dtDate);
var lIntval = parseInt(NumDay);
date.setMonth(date.getMonth() + lIntval);
return date.getYear() +'-' + (date.getMonth()+1) + '-' +date.getDate();
}
addDate("2008-01-01".replace(/-/g, "\/"),2);
=======================================
// addDate("5",5,"2004/12/1 00:00:00")
function addDate(type,NumDay,dtDate){
var date = new Date(dtDate)
type = parseInt(type) //類型
lIntval = parseInt(NumDay)//間隔
switch(type){
case 6 ://年
date.setYear(date.getYear() + lIntval)
break;
case 7 ://季度
date.setMonth(date.getMonth() + (lIntval * 3) )
break;
case 5 ://月
date.setMonth(date.getMonth() + lIntval)
break;
case 4 ://天
date.setDate(date.getDate() + lIntval)
break
case 3 ://時
date.setHours(date.getHours() + lIntval)
break
case 2 ://分
date.setMinutes(date.getMinutes() + lIntval)
break
case 1 ://秒
date.setSeconds(date.getSeconds() + lIntval)
break;
default:
}
return date.getYear() +'-' + (date.getMonth()+1) + '-' +date.getDate()+
' '+ date.getHours()+':'+date.getMinutes()+':'+date.getSeconds()
}
DWR不能識別以
Class c = Class.forName(ClassName);
方式產生的對象,
它被是別為java.lang.Class
隨機快速排序算法:
還沒怎么整明白,有點暈
Java語言:
import java.util.*;
public class Test {
int[] x = {3,7,5,6,4,9,8,1};
int comps = 0;
void quicksort(int l, int u)
{
int i, m;
if (l >= u) return;
swap(l, getRandom(l, u));
m = l;
comps += u - 1;
for (i = l+1; i <= u; i++){
//comps++;
if (x[i] < x[l])
swap(++m, i);
}
swap(l, m);
quicksort(l, m-1);
quicksort(m+1, u);
}
void swap(int a,int b){
int temp = x[a];
x[a] = x[b];
x[b] = temp;
}
int getRandom(int min,int max){
return (int)(Math.random()*(max-min+1)) + min;
//Math.round(Math.random()*(Max-Min)+Min);
}
public static void main(String[] args) {
Test t = new Test();
System.out.println(Arrays.toString(t.x));
t.quicksort(0,t.x.length - 1);
System.out.println(t.comps);
System.out.println(Arrays.toString(t.x));
}
}
好久沒寫了
中間過了個十一,在家混沌過了好幾天
回來轉眼上了一星期班了,忙的屁滾尿流
一年前的系統要增加兩個大功能,200多個報表要挨個修改,報表校驗的頁面效果客戶又提出了新建議,一個字 改
從昨天晚上開始搗鼓到現在終于解決了一個問題,心情好了些,上來寫寫,哈哈
這兩天用了baidu 百度空間中的彈出窗口js,感覺不錯,很強大,很好很簡單的解決了好幾個問題,界面友好度以及美化也好多了,以前都是硬邦邦window.open();
有興趣的朋友搜索"百度 popup"就好了,已經有人給出了注釋,強大。
最有意思的是用javascript獲取和設置style
DOM標準引入了覆蓋樣式表的概念,當我們用document.getElementById("id").style.backgroundColor 獲取樣式時 獲取的只是id中style屬性中設置的背景色,如果id中的style屬性中沒有設置background-color那么就會返回空,也就是說如果id用class屬性引用了一個外部樣式表,在這個外部樣式表中設置的背景色,那么不好意思document.getElementById("id").style.backgroundColor 這種寫法不好使,如果要獲取外部樣式表中的設置,需要用到window對象的getComputedStyle()方法,代碼這樣寫window.getComputedStyle(id,null).backgroundColor
但是兼容問題又來了,這么寫在firefox中好使,但在IE中不好使
兩者兼容的方式寫成
window.getComputedStyle?window.getComputedStyle(id,null).backgroundColor:id.currentStyle["backgroundColor"];
如果是獲取背景色,這種方法在firefox和IE中的返回值還是不一樣的,IE中是返回"#ffff99"樣子的,而firefox中返回"rgb(238, 44, 34) "
值得注意的是:window.getComputedStyle(id,null)這種方式不能設置樣式,只能獲取,要設置還得寫成類似這樣id.style.background="#EE2C21";
參考:
JavaScript權威指南
http://bokee.shinylife.net/blog/article.asp?id=817
http://book.csdn.net/bookfiles/679/10067921329.shtml
早上,
上班,
公司樓下等電梯,
旁邊站一男子,
微微發福,
個不高,
遂俯視,
手拿車鑰匙(大大的那種帶遙控的那種明顯汽車鑰匙),
另一手拿一大塊手機(智能的手寫的那種),擺弄著
肩背筆記本,
嶄新嶄新的,
頓生羨慕,
羨慕ing,
往上看,
面色紅潤,
一看就是吃了早飯了,
再往上,
短發,
1/3白色,
遂心想:嗯,等我也這些白頭發了,
我也背這些裝備,
呵呵,咧嘴......
今天發現一個好東西
Url Rewrite Filter
它可以實現url重寫,從而隱藏實際的url,同時使url看起來更美觀,簡單
最令人興奮的是它一下解決了一值在尋找的blog用戶訪問自己的空間的問題
比如http://hi.baidu.com/liuspring 就顯示我的空間
1、下載Url Rewrite Filter
2、在項目的web.xml配置過濾器
XML語言:
<filter>
<filter-name>UrlRewriteFilter</filter-name>
<filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
<init-param>
<param-name>logLevel</param-name>
<param-value>debug</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>UrlRewriteFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
3、將urlrewrite-2.6.0.jar放入lib文件夾
4、新建urlrewrite.xml文件置于WEB-INF目錄
5、配置urlrewrite.xml
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE urlrewrite PUBLIC "-//tuckey.org//DTD UrlRewrite 2.6//EN"
"http://tuckey.org/res/dtds/urlrewrite2.6.dtd">
<!--
Configuration file for UrlRewriteFilter
http://tuckey.org/urlrewrite/
-->
<urlrewrite>
<rule>
<from>^/([a-z]+)/?$</from>
<to type= "forward" >/blogView.do?go=$1</to>
</rule>
<rule>
<note> 這是一個通用請求url rewrite</note>
<from>^/([a-z0-9A-Z_]+)/([a-z0-9A-Z_]+)/?$</from>
<to type= "forward" >/$2.do?go=$1</to>
</rule>
<outbound-rule>
<note>
The outbound-rule specifies that when response.encodeURL is called (if you are using JSTL c:url)
the url /rewrite-status will be rewritten to /test/status/.
The above rule and this outbound-rule means that end users should never see the
url /rewrite-status only /test/status/ both in thier location bar and in hyperlinks
in your pages.
</note>
<from>/rewrite-status</from>
<to>/test/status/</to>
</outbound-rule>
</urlrewrite>
url匹配使用正則表達式的規則,
實驗中發現一個問題,就是必須把里面的正則表達式用小括號括起來,在正則表達式中叫分組
不然會報異常:
java.lang.IndexOutOfBoundsException: No group 2
哈哈,前幾日還費勁的自己寫Servlet重寫url呢,原來這有現成的,更加覺得自己現在的水平遇到的問題網上的前輩們早都遇到過了,一定要站在巨人的肩膀上,少走彎路啊。
把我的servlet貼在這,呵呵,參考自blojsom
package com.capinfo.servlet;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.capinfo.util.PageConstraint;
import com.capinfo.util.PigBlogUtil;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
/**
*
* @author Administrator
*
*/
public class PigBlogServlet extends HttpServlet {
protected Log _logger = LogFactory.getLog(PigBlogServlet.class);
/**
* Initialize
*
* @param servletConfig {@link ServletConfig}
* @throws ServletException If there is an error initializing
*/
public void init(ServletConfig servletConfig) throws ServletException {
super.init(servletConfig);
}
/**
* Handle requests made to
*
* @param httpServletRequest {@link HttpServletRequest} request
* @param httpServletResponse {@link HttpServletResponse} response
* @throws ServletException If there is an error serving the request
* @throws IOException If there is an error serving the request
*/
protected void service(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws ServletException, IOException {
// Make sure that we have a request URI ending with a / otherwise we need to
// redirect so that the browser can handle relative link generation
// if (!httpServletRequest.getRequestURI().endsWith("/")) {
// StringBuffer redirectURL = new StringBuffer();
// redirectURL.append(httpServletRequest.getRequestURI());
// redirectURL.append("/");
// if (httpServletRequest.getParameterMap().size() > 0) {
// redirectURL.append("?");
// redirectURL.append(PigBlogUtil.convertRequestParams(httpServletRequest));
// }
//
// if (_logger.isDebugEnabled()) {
// _logger.debug("Redirecting the user to: " + redirectURL.toString());
// }
//
// httpServletResponse.sendRedirect(redirectURL.toString());
//
// return;
// }
// Check for an overriding id
String blogId = httpServletRequest.getParameter(PageConstraint.GO);
if (PigBlogUtil.checkNullOrBlank(blogId)) {
String blogIdFromPath = PigBlogUtil.getBlogFromPath(httpServletRequest.getPathInfo());
if (blogIdFromPath == null) {
blogId = PageConstraint.GO1;
} else {
blogId = blogIdFromPath;
}
}
if (PigBlogUtil.checkNullOrBlank(blogId)) {
httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "Blog ID not specified");
return;
}
StringBuffer redirectURL = new StringBuffer();
//redirectURL.append(httpServletRequest.getContextPath());
System.out.println(httpServletRequest.getRequestURI());
if(httpServletRequest.getRequestURI().indexOf("/blog/") > -1 && httpServletRequest.getRequestURI().indexOf(".jsp") == -1 ){
if(!httpServletRequest.getRequestURI().endsWith("/") && httpServletRequest.getRequestURI().indexOf(".do") > -1){
redirectURL.append(httpServletRequest.getRequestURI().substring(httpServletRequest.getRequestURI().lastIndexOf("/"), httpServletRequest.getRequestURI().length()));
}else if(httpServletRequest.getRequestURI().indexOf("/blog/") == -1){
}else{
redirectURL.append("/blogView.do");
}
redirectURL.append("?go=");
redirectURL.append(blogId);
httpServletRequest.getRequestDispatcher(redirectURL.toString())
.forward((ServletRequest)httpServletRequest, (ServletResponse)httpServletResponse);
//httpServletResponse.sendRedirect(redirectURL.toString());
}else{
httpServletRequest.getRequestDispatcher(httpServletRequest.getRequestURI())
.forward((ServletRequest)httpServletRequest, (ServletResponse)httpServletResponse);
//httpServletResponse.sendRedirect(httpServletRequest.getRequestURI());
}
System.out.println(redirectURL.toString());
return;
}
/**
* Take out of service
*/
public void destroy() {
super.destroy();
if (_logger.isDebugEnabled()) {
_logger.debug(" destroyed");
}
}
}