`
guochongcan
  • 浏览: 321128 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

point: [x=0 , y=0] 得不到值(struts2类型转换,初学struts2)

    博客分类:
  • SSH
阅读更多
point: [x=0 , y=0] 得不到值(struts2类型转换,初学struts2)
悬赏:5 发布时间:2009-02-17 提问人:guochongcan (初级程序员)
input.jsp


<%@ page language="java" import="java.util.*" pageEncoding="GB18030"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
   
    <title>My JSP 'input.jsp' starting page</title>
   
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">   
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->

  </head>
 
  <body>
    <s:form action="pointConverter" method="post">
    <s:textfield name="point" label="point"></s:textfield><br>
    <s:textfield name="age" label="age"></s:textfield><br>
    <s:textfield name="username" label="username"></s:textfield><br>
    <s:textfield name="birthday" label="birthday"></s:textfield><br>
    <s:submit></s:submit>
    </s:form>
  </body>
</html>


output.jsp


<%@ page language="java" import="java.util.*" pageEncoding="GB18030"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
   
    <title>My JSP 'output.jsp' starting page</title>
   
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">   
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->

  </head>
 
  <body>
    point: <s:property value="point"/><br>
    age: <s:property value="age"/><br>
    username: <s:property value="username"/><br>
    birthday: <s:property value="birthday"/><br>
  </body>
</html>





PointAction.java


package com.action;

import java.util.Date;

import com.opensymphony.xwork2.ActionSupport;
import com.bean.Point;

public class PointAction extends ActionSupport{

private Point point;
private int age;
private String username;
private Date birthday;
public Point getPoint() {
return point;
}
public void setPoint(Point point) {
this.point = point;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public Date getBirthday() {
return birthday;
}
public void setBirthday(Date birthday) {
this.birthday = birthday;
}
@Override
public String execute() throws Exception {

return SUCCESS;
}


}




Point.java


package com.bean;

public class Point {

private int x;
private int y;
public int getX() {
return x;
}
public void setX(int x) {
this.x = x;
}
public int getY() {
return y;
}
public void setY(int y) {
this.y = y;
}


}




PointConverter.java


package com.converter;

import java.util.Map;

import ognl.DefaultTypeConverter;

import com.bean.Point;

public class PointConverter extends DefaultTypeConverter {

@Override
public Object convertValue(Map context, Object value, Class toType) {
if(Point.class == toType){

Point point = new Point();

String[] str = (String[])value;

String[] paramValues = str[0].split(",");

int x = Integer.parseInt(paramValues[0]);
int y = Integer.parseInt(paramValues[1]);

point.setX(x);
point.setY(y);

return point;

}
if(String.class == toType){

Point point = new Point();

int x = point.getX();
int y = point.getY();

String result = "[x=" + x + " , y=" +y + "]";
//System.out.println(result);
return result;
}
return null;
}


}



struts.xml


<?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="struts2" extends="struts-default">
    <action name="login" class="com.action.LoginAction">
    <result name="success">/success.jsp</result>
    <result name="input">/index.jsp</result>
    </action>
   
    <action name="pointConverter" class="com.action.PointAction">
    <result name="success">/output.jsp</result>
    </action>
    </package>
    </struts>




PointAction-conversion.properties

point=com.converter.PointConverter





得到的结果是

point: [x=0 , y=0]
age: 88
username: zhangsan
birthday: 08-11-11




point: [x=0 , y=0] 输入值了(34,23),为什么得不到值呢?请各位帮忙看看


自己找到答案了,再写在这后面。

找到了
PointConverter.java 里面

if(String.class == toType){

Point point = new Point();

又new 了一个Point
直接Point point = (Point)value;
就行。
1
0
分享到:
评论

相关推荐

    flash特效【包括源代码】

    public function Point3D(x1:Number=0,y1:Number=0,z1:Number=0) { this.x = x1; this.y = y1; this.z = z1; } public function clone():Point3D { outputPoint = new Point3D(); output...

    Struts2 ConverterType类型转换 案例源码

    例如前台页面的Input框,我们输入一个坐标(x,y),通过Struts2配置,我们可以把前台输入的坐标自动给 Point Entity 的两个属性 int x 、int y 自动赋值!

    用Python自定义三维向量类,实现加减乘除等运算

    用Python自定义三维向量类,实现加减乘除等运算: #构造方法,初始化,定义向量坐标 def __init__(self, x, y, z): self.__x = x self.__y = y self.__z = z ... y = self.__y - anotherPoint.__y

    水面杂点滤镜

    offsets[0].x = offsets[0].x + 20; offsets[0].y = offsets[0].y - 20; img.filters = [new DisplacementMapFilter(bmd, new Point(0, 0), channelOptions, channelOptions, 10, 10)]; }) ...

    Python求两点之间的直线距离(2种实现方法)

    def __init__(self,x=0,y=0): self.x=x self.y=y def getx(self): return self.x def gety(self): return self.y #定义直线函数 class Getlen: def __init__(self,p1,p2): self.x=p1.getx()-p2.getx() ...

    类似QQ,MSN的窗口震动效果

    Result := IfThen(RandomRange(0, 36635) mod 2 = 0, -1, 1); end; begin Randomize; for I := Max_PTCount - 1 downto 0 do begin FPTArray[i].X := Sign()*RandomRange(0, 36635) mod FXStrength*i div ...

    Delphi 实现图像热点功能.rar

     thepoint[2]:=point(105,183);  thepoint[3]:=point(129,201);  thepoint[4]:=point(188,92);  thepoint[5]:=point(135,99);  count:=5;//四边形顶点数目,首末点为一点  fourE_rgn:=CreatePolygonRgn(the...

    MATLAB拉格朗日插值法程序

    n=size(pointx,2); L=ones(n,size(x,2)); if (size(pointx,2)~=size(pointy,2)) fprintf(1,'\nERROR!\nPOINTX and POINTY must have the same number of elements\n'); y=NaN; else for i=1:n for j=1:n if (i~...

    c++程序设计相关

    Point(int x=0,int y=0):XX(x),YY(y) {} Point operator+(const Point &a2) const; Point operator-(const Point &a2) const; void display() const; private: int XX; int YY; }; Point Point::operator+...

    Android代码-自定义圆形拖动条

    SwagPoints SwagPoints - An Android ... android:id="@ id/seekbar_point" android:layout_width="match_parent" android:layout_height="340dp" android:layout_gravity="center" android:padding="64dp

    AS3坦克大战源代码 教程

    [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3] ]; public function Main() { // constructor code var sence:Sence.MapSence = new Sence....

    sensor_msgs::LaserScan转换为sensor_msgs::PointCloud2

    用于2d雷达生成点云地图,可在我的主页找使用教程

    duckietown-serialization

    def __init__ ( self , x , y ): self . x = x self . y = y 现在您可以加载: s = """ ~Point: x: 0 y: 1 """ from duckietown_serialization_ds1 import Serializable import yaml data = yaml . load ( s ) ...

    单片后方交会

    #define point_num 6 //控制点数量 using namespace std; const int n=6; template,typename T2&gt;void transpose (T1*mat1,T2*mat2,int a,int b); template,typename T2&gt;void multi(T1*mat1,T2 * mat2,T2 * result,...

    GIS坐标转换 JAVA版

    用于GIS各坐标的转换! 我是为了将EPSG:4326坐标转换成EPSG:900913坐标,找到的工具,然后添加了两者之间的转换方式! 使用方式: private static Projection proj = ... return new double[] { dst.x, dst.y }; }

    谷歌地图 delphi 封装库 2013 0.1.9 全面支持google maps api

    - Improvement: TLatLngEvent -&gt; the events of this type now have a new parametre, X and Y, of Real type, with information of point (X,Y) - Improvement: TLinkedComponent -&gt; added ShowInfoWinMouseOver ...

    免费QRcode组件,效果很好

    PixelSize : The size of the one image point. Level : The error correction level } class procedure GenerateBitmapFile(const FileName : string; const Text : string; Margin : integer = 4; PixelSize : ...

    基于c++数字逻辑电子仿真器

    ClientDC.BitBlt (point.x ,point.y,bmpInfo.bmWidth ,bmpInfo.bmHeight,&dc,0,0,SRCAND); dc.SelectObject (pOldBitmap);  用全局变量bmWidth和bmHeight来保存元件的宽度和高度 bmWidth=bmpInfo.bmWidth ; ...

    elk:适用于Python的驼鹿式对象系统

    概要import elkclass Point(elk.Elk): x = elk.ElkAttribute(mode='rw', type=int) y = elk.ElkAttribute(mode='rw', type=int) def clear(self): self.x = 0 self.y = 0class Point3D(Point): z = elk.ElkAttribute...

    计算机图形学 DDA画直线

    求x,y的增量tx,ty,求步数n(tx,ty最大值),x,y赋初值为起点,求出每步的增量dx,dy,定义点point,并赋初值,point.x=int(x);point.y=int(y+0.5) ,判断i,画点;确定下一个点 x=x+dx;y=y+dy;i++

Global site tag (gtag.js) - Google Analytics