blaze

欢迎来到blaze>>   | 首页 资源中心 | solaris | Ruby on rails | ajax | oracle | JCOM | tapestry | WorkFlow | 我的项目 | JSF | 乱七八糟 | spring | opensource | struts | hibernate | eclipse | 灵光乍现 | ITPUB论坛

struts国际化带来的javascript 中文乱码问题 解决方案

发表人:fourfire | 发表时间: 2005年八月07日, 22:19

由于引入struts用了UTF-8来编码后,javascript就不能正确输出中文
并非在页面上hidden一些<bean:message/>

应该这样做

 查看全文

tiles初试

发表人:fourfire | 发表时间: 2005年一月28日, 12:16

用tiles把主页作了重构,希望能够动态改变首页的大部分属性 查看全文

struts 学习小记

发表人:fourfire | 发表时间: 2005年一月19日, 18:38

size、index 查看全文

struts学习小记5

发表人:fourfire | 发表时间: 2004年十月30日, 18:55

对validate进行的使用,有了一定的认识 查看全文

一个奇怪的问题

发表人:fourfire | 发表时间: 2004年十月27日, 09:42

struts与tomcat版本不同发现的问题 查看全文

struts 小记4

发表人:fourfire | 发表时间: 2004年九月23日, 15:18

最近很忙,没有写东西。

沟通说起来简单,做起来难。

 查看全文

struts学习小记3

发表人:fourfire | 发表时间: 2004年九月10日, 14:05

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

发表人:fourfire | 发表时间: 2004年九月08日, 15:41

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">
&nbsp;
</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

发表人:fourfire | 发表时间: 2004年九月07日, 13:50

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">
&nbsp;
</logic:notPresent>

等同于

<%=(welcomeFeeBean==null?"&nbsp;":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>


Valid XHTML 1.0 Strict and CSS. Powered by pLog
Design by Blog.lvwo.com