| « | 五月 2012 | » | ||||
|---|---|---|---|---|---|---|
| 一 | 二 | 三 | 四 | 五 | 六 | 日 |
| 1 | 2 | 3 | 4 | 5 | 6 | |
| 7 | 8 | 9 | 10 | 11 | 12 | 13 |
| 14 | 15 | 16 | 17 | 18 | 19 | 20 |
| 21 | 22 | 23 | 24 | 25 | 26 | 27 |
| 28 | 29 | 30 | 31 | |||
由于引入struts用了UTF-8来编码后,javascript就不能正确输出中文
并非在页面上hidden一些<bean:message/>
应该这样做
查看全文用tiles把主页作了重构,希望能够动态改变首页的大部分属性 查看全文
size、index 查看全文
对validate进行的使用,有了一定的认识 查看全文
struts与tomcat版本不同发现的问题 查看全文
struts学习小记3
1 比较
<logic:greaterEqual>
</logic:greaterEqual>
等同于
>=,用法与小记2中类似
<logic:lessEqual>
</logic:lessEqual>
等同于
<=,用法与小记2中类似
2 对于时间类型的属性的处理
显示:
java.util.Date:<bean:write name="welcomeFeeBean" formatKey="global.formatDate"
property="cardDate"/>
java.util.Calendar:<bean:write name="welcomeFeeBean" formatKey="global.formatDate"
property="cardDate.time"/>
页面form生成bean:
增加类(处理Calendar的处理类,Date型稍作改动):
public class DateConvert implements Converter
{
static SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
public DateConvert()
{
}
public Object convert(Class type, Object value)
{
if(value==null)return null;
if(((String)value).trim().length()==0) return null;
if(value instanceof String)
{
try
{
Calendar cal=Calendar.getInstance();
cal.setTime(df.parse((String)value));
return cal;
}
catch (Exception ex)
{
throw new ConversionException("输入的日期类型不合乎yyyy-MM-dd"
+ value.getClass());
}
}
else
{
throw new ConversionException("输入的不是字符类型"+value.getClass());
}
}
}
在servlet中注册
ConvertUtils.register(new DateConvert(),java.util.Calendar.class);
对于jsp中的处理,我沿用以前的办法用<%...%>(可能是没找到更好的办法)
3 几点疑问
a)怎样实现
<html:link page="<%=((com.longtop.oa.bean.WelcomeFeeBean)welcomeFeeBean).getBillSource()%>"
target="_blank">
即链接放在库中
b)怎样访问页面中的bean
struts学习小记2
1 比较
等于:
<logic:equal name="welcomeFeeBean" property="confirmNum" value="2">
。。。
</logic:equal>
等同于:
if(welcomeFeeBean.confirmNum()==2)
{
}
大于:(不包含=)
<logic:greaterThan name="welcomeFeeBean" property="confirmNum" value="2">
</logic:greaterThan>
等同于:
if(welcomeFeeBean.confirmNum()>2)
{
}
小于:(不包含=)
<logic:lessThan name="welcomeFeeBean" property="confirmNum" value="2">
</logic:lessThan>
等同于:
if(welcomeFeeBean.confirmNum()<2)
{
}
2 链接
<html:link page='/a.jsp?oper=view' target="_blank" paramId="pid" paramName="welcomeFeeBean" paramProperty="id">
等同于:
<a href="/a.jsp?oper=view&pid=<%=welcomeFeeBean.getId()%>" target="_blank">
3 用反射方法,解决struts中文问题,利用反射,转换编码
public static void beanEnocdePropertySet(Object rec)
{
Field[] fields = rec.getClass().getDeclaredFields();
for (int i = 0; i < fields.length; i++)
{
String tmp = fields[i].getName();
String getMethodName =
"get" + tmp.substring(0, 1).toUpperCase() + tmp.substring(1);
String setMethodName =
"set" + tmp.substring(0, 1).toUpperCase() + tmp.substring(1);
try
{
Method getMethod =
rec.getClass().getMethod(getMethodName, null);
if (getMethod.getReturnType().getName() == "java.lang.String")
{
rec
.getClass()
.getMethod(
setMethodName,
new Class[] { getMethod.getReturnType()})
.invoke(
rec,
new Object[] {
CommonFunction.ISO88592GB2312(
(String) rec.getClass().getMethod(
getMethodName,
null).invoke(
rec,
null))});
}
}
catch (IllegalArgumentException e)
{
e.printStackTrace();
}
catch (SecurityException e)
{
e.printStackTrace();
}
catch (IllegalAccessException e)
{
e.printStackTrace();
}
catch (InvocationTargetException e)
{
e.printStackTrace();
}
catch (NoSuchMethodException e)
{
e.printStackTrace();
}
}
}
struts标签:
1 判断空值
<logic:notPresent scope="request" name="personcols">
<jsp:forward page="/welcomefeesearch.do">
<jsp:param name="type" value='add' />
</jsp:forward>
</logic:notPresent>
<logic:present scope="request" name="personcols">
...
</logic:present>
等同于
personcols=(Collection)request.getAttribute("personcols");
if(personcols==null)
{
response.sendRedirect("/welcomefeesearch.do");
}
else
{
...
}
-------
<logic:present name="welcomeFeeBean" property="manId">
<bean:write name="welcomeFeeBean" property="manId"/>
</logic:present>
<logic:notPresent name="welcomeFeeBean" property="manId">
</logic:notPresent>
等同于
<%=(welcomeFeeBean==null?" ":welcomeFeeBean.getManId()%>
2 显示格式化
方法一:
<bean:write name="welcomeFeeBean" formatKey="global.formatDate" property="makedate.time"/>
在属性文件中配置
global.formatDate=yyyy-MM-dd
方法二:
<bean:write name="welcomeFeeBean" format="¥###,###.###" property="eatFee"/>
<bean:write name="welcomeFeeBean" format="yyyy-MM-dd" property="makedate.time"/>
3 迭代
<logic:iterate>
</logic:iterate>
用迭代生成下拉列表框
<select size="1" name="jiedaidanwei">
<option selected value="-1">请选择接待单位</option>
<logic:iterate id="departmentBean" name="departmentcols" >
<option value="<bean:write name='departmentBean' property='id'/>"><bean:write
name="departmentBean" property="name"/></option>
</logic:iterate>
</select>















