问题描述
packagecom.action;importjava.util.Date;importjavax.servlet.http.HttpServletRequest;importorg.apache.struts2.ServletActionContext;importcom.opensymphony.xwork2.ActionSupport;publicclassActionInfoextendsActionSupport{privatepointpoint;privateStringusername;privateintage;privateDatebrithday;publicpointgetPoint(){returnpoint;}publicvoidsetPoint(pointpoint){this.point=point;}publicStringgetUsername(){returnusername;}publicvoidsetUsername(Stringusername){this.username=username;}publicintgetAge(){returnage;}publicvoidsetAge(intage){this.age=age;}publicDategetBrithday(){returnbrithday;}publicvoidsetBrithday(Datebrithday){this.brithday=brithday;}@OverridepublicStringexecute()throwsException{System.out.println("请求leaction");HttpServletRequestrequest=ServletActionContext.getRequest();request.setAttribute("point",point);returnSUCCESS;}//publicvoidvalidate(){////TODOAuto-generatedmethodstub//super.validate();}packagecom.action;importjava.util.Map;importorg.apache.struts2.util.StrutsTypeConverter;publicclassconverterextendsStrutsTypeConverter{@OverridepublicObjectconvertFromString(Maparg0,String[]str,Classarg2){String[]string=str[0].split("-");//String[]string=arg1[0].split("-");pointpoint=newpoint();point.setX(Integer.parseInt(string[0]));point.setY(Integer.parseInt(string[1]));point.setZ(Integer.parseInt(string[2]));returnpoint;}@OverridepublicStringconvertToString(Maparg0,Objectob){pointpoint=(point)ob;intx=point.getX();inty=point.getY();intz=point.getZ();return"[x="+x+","+"y="+y+","+"z="+z+"]";}}packagecom.action;publicclasspoint{privateintx;privateinty;privateintz;publicintgetX(){returnx;}publicvoidsetX(intx){this.x=x;}publicintgetY(){returny;}publicvoidsetY(inty){this.y=y;}publicintgetZ(){returnz;}publicvoidsetZ(intz){this.z=z;}//publicStringtoString()//{//return"[x="+x+","+"y="+y+","+"z="+z+"]";//}}
解决方案
解决方案二:
请大家帮我看看我的这个struts2的类型转换问题我在jsp页面输入任何东西都是显示不是有效的字段谢谢大家
解决方案三:
struts2还没看过那
解决方案四:
你是研究struts2之前的版本的?
解决方案五:
你确定他有执行转型的这个类??如果执行了就不应该你看看有执行没你就提供这点信息我是没法解决望高手关注
解决方案六:
楼主你提供的信息不全,首先struts2有内置的类型转换器,可以进行int和date等到String的简单转换。默认就能用。还用,自定义的类型转换器,基于OGNL的类型转换器,你是想用哪种啊?要是基于OGNL的类型转换器,只需重写execute()方法就行了,然后再jsp页面上设置标签,struts2里配置。不是很难的。converter是什么意思啊?
解决方案七:
看看你是不是在页面上使用的是属性接收的,如果是的你当然需要类型转换了。