我想写个对piont自定义转换的程序可是出现了如下的错误
2008-12-7 18:43:10 org.apache.struts2.dispatcher.Dispatcher serviceAction
严重: Could not find action or result
No result defined for action com.test.PointAction and result input - action - file:/E:/Documents%20and%20Settings/Administrator/workspace/struts2/WebRoot/WEB-INF/classes/struts.xml:13:62
at com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:350)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:253)
at com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:150)
at org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:48)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:86)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
at com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:123)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:186)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:86)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
at com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:105)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
我的源文件如下
LoginActin.java文件。
package com.test;import com.opensymphony.xwork2.ActionSupport;public class LoginAction extends ActionSupport {
/**
*
*/
private static final long serialVersionUID = 1L;
String username;
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
{
if("hello".equals(this.getUsername().trim())&&"world".equals(this.getPassword().trim()))
{
return "success";
}
else
{
this.addFieldError("password", "username or password is Error");
return "failer";
}
}
public void validate() {
// TODO Auto-generated method stub
if(null==this.getUsername()||"".equals(this.getUsername().trim()))
{
this.addFieldError("username", "username is null");
}
if(null==this.getPassword()||"".equals(this.getPassword().trim()))
{
this.addFieldError("password", "password is null");
}
}
}
2008-12-7 18:43:10 org.apache.struts2.dispatcher.Dispatcher serviceAction
严重: Could not find action or result
No result defined for action com.test.PointAction and result input - action - file:/E:/Documents%20and%20Settings/Administrator/workspace/struts2/WebRoot/WEB-INF/classes/struts.xml:13:62
at com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:350)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:253)
at com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:150)
at org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:48)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:86)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
at com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:123)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:186)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:86)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
at com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:105)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
我的源文件如下
LoginActin.java文件。
package com.test;import com.opensymphony.xwork2.ActionSupport;public class LoginAction extends ActionSupport {
/**
*
*/
private static final long serialVersionUID = 1L;
String username;
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
{
if("hello".equals(this.getUsername().trim())&&"world".equals(this.getPassword().trim()))
{
return "success";
}
else
{
this.addFieldError("password", "username or password is Error");
return "failer";
}
}
public void validate() {
// TODO Auto-generated method stub
if(null==this.getUsername()||"".equals(this.getUsername().trim()))
{
this.addFieldError("username", "username is null");
}
if(null==this.getPassword()||"".equals(this.getPassword().trim()))
{
this.addFieldError("password", "password is null");
}
}
}
package com.test.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;
}}
PointAction.java文件package com.test;
import java.util.Date;
import com.opensymphony.xwork2.ActionSupport;
import com.test.bean.Point;
public class PointAction extends ActionSupport {
/**
*
*/
private Point point=null;
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;
}
public String execute() throws Exception {
// TODO Auto-generated method stub
return SUCCESS;
}
}
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.test.LoginAction">
<result name="input">/login3.jsp</result>
<result name="success">/result.jsp</result>
<result name="failer">/login3.jsp</result>
</action>
<action name="pointConverter" class="com.test.PointAction">
<result name="success">/output.jsp</result>
</action>
</package>
</struts>
Point=com.coverter.PointConverterPointConverterv.java文件
package com.coverter;
import java.util.Map;import com.test.bean.Point;import ognl.DefaultTypeConverter;public class PointConverter extends DefaultTypeConverter { public Object convertValue(Map context, Object value, Class toType) {
// TODO Auto-generated method stub
if(Point.class==toType)
{
Point point=new Point();
String []str=(String [])value;
String []paramValue=str[0].split(",");
int x=Integer.parseInt(paramValue[0]);
int y=Integer.parseInt(paramValue[1]);
point.setX(x);
point.setY(y);
return point;
}
if(String.class==toType)
{
Point point =(Point)value;
int x=point.getX();
int y=point.getY();
String result="[x="+x+","+"y="+y+"]";
return result;
}
else
return null;
}}
<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%@taglib prefix="s" uri="/struts-tags" %><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>"> <title>My JSP 'login2.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>
<h3>please input dou hao </h3>
<body>
<s:form action="pointConverter">
<s:textfield name="point" label="point"> </s:textfield>
<s:textfield name="age" label="age"></s:textfield>
<s:textfield name="username" label="username"></s:textfield>
<s:textfield name="birthday" label="birthday"></s:textfield>
<s:submit label="submit"></s:submit>
</s:form>
</body>
</html>
当输入信息后出现如下错误
type Status reportmessage No result defined for action com.test.PointAction and result inputdescription The requested resource (No result defined for action com.test.PointAction and result input) is not available.
No result defined for action com.test.PointAction and result input - action - file:/E:/Documents%20and%20Settings/Administrator/workspace/struts2/WebRoot/WEB-INF/classes/struts.xml:13:62
你仔细检查一下你的配置文件
原因:在类型转换发生错误后,要显示错误信息。必须配置input。
我的PointAction明明只返回了success怎么会有input呢
找了一下午 最后通过比较 才发现自己的转型类中自己多敲了一行代码if (Point.class == toType) {
Point point = new Point();
String values[] = (String[]) value;
String parameter[] = values[0].split(",");
!!!!!!!!//System.out.println(values[1]);
int x = Integer.parseInt(parameter[0]);
int y = Integer.parseInt(parameter[1]);
point.setX(x);
point.setY(y);
return point;
}
只是为了试试能否输出。 我发现用Struts2时报错机制实在是差的可怜 要是用servlet什么的 一眼就能看出来的 真不知道以后找错会是个什么样子
要检查这种错误时,可以
1,在后台action类中重写ActionSupport中的
void addActionError(String anErrorMessage)
void addActionMessage(String aMessage)
void addFieldError(String fieldName, String errorMessage)
这三个方法,在并在其实现代码中设置断点,监控传入的参数,并可获知页面的相关报错具体原因.
2,在页面中加入以下标签,将错误显示出来:
<div style=”color:red”>
<s:fielderror />
</div>
Point=com.coverter.PointConverterpublic class PointConverter extends DefaultTypeConverter {public Object convertValue(Map context, Object value, Class toType) {
// TODO Auto-generated method stub
if(Point.class==toType)
{
Point point=new Point();这里错了吧,属性文件里的属性(是属性的名字不是属性所属类的名字)应该和action类里的属性的名字一样(注意大小写)。
出现上述问题的一个常见原因就是把属性文件的名字写错( 被类型转换的action的类名-conversion.properties 例如PointAction中有对象类型的属性需要转换类型,那么在PointAction的同级目录里就应该有个PointAction-conversion.properties(红色的为固定不变的) 文件,那么在)或者里面的内容写错了。
在2.0中一切OK,没有问题,但是在2.1中确出现了No result defined for action的异常,郁闷了好半天,经过多方查找,原来是在2.1中有一个插件struts2-convention-plugin-2.1.8.jar,这个插件是2.1版本中新添加的默认核心包,这个插件是实现Struts2的零配置(稍后会详细解释这个插件的使用),但是这样问题就来了,如果引入就必须引入namespace命名空间,否则就会出现刚才的No result defined for action的异常
复制别人的......
我也出现这个问题
感谢,我加上namaspace就好了。
我的解决办法是:
:改/uapSecond/WebRoot/jsp/uaphost/uaphostlist.jsp为/uapSecond/WebRoot/jsp/uaphost/uaphost.jsp
jsp的命名应该是有内在约定
<s:form action="pointConverter">
<s:textfield name="point" label="point"> </s:textfield>
<s:textfield name="age" label="age"></s:textfield>
<s:textfield name="username" label="username"></s:textfield>
<s:textfield name="birthday" label="birthday"></s:textfield>
<s:submit label="submit"></s:submit>
</s:form>
</body>
红色部分写错了,把label改为type,试试!!!!!!!!!!!!
Point point = new Point();
String values[] = (String[]) value;
String parameter[] = values[0].split(",");
!!!!!!!!//System.out.println(values[1]);
int x = Integer.parseInt(parameter[0]);
int y = Integer.parseInt(parameter[1]);
point.setX(x);
point.setY(y);
return point;
}
Point point = new Point();
String values[] = (String[]) value;
String parameter[] = values[0].split(",");
!!!!!!!!//System.out.println(values[1]);
int x = Integer.parseInt(parameter[0]);
int y = Integer.parseInt(parameter[1]);
point.setX(x);
point.setY(y);
return point;
}
<constant name="struts.devMode" value="true"></constant>
<package name="struts2" extends="struts-default" namespace="/">
<action name="addSchedule" class="com.qhit.myoffice.schedule.action.AddScheduleAction">
<result name="success">page/scheduleManage/addSchedule.jsp</result>
<result name="input">page/scheduleManage/addSchedule.jsp</result>
</action>
<action name="myScheduleList" class="com.qhit.myoffice.schedule.action.MyScheduleListAction">
<result name="success">page/scheduleManage/MyScheduleList.jsp</result>
<result name="input">page/scheduleManage/MyScheduleList.jsp</result>
</action>
<action name="mynote" class="com.qhit.myoffice.schedule.action.MynoteAction">
<result name="success">page/scheduleManage/MyNote.jsp</result>
<result name="input">page/scheduleManage/MyNote.jsp</result>
</action>
</package>
</struts> 我的还是那种错误
Timestamp endTime=ServletActionContext.getRequest().getParameter("endTime");
这个总是报错,请问这个怎么转换啊
这个错误就是说没有为返回的input定义,可是有时候我们不一定要这个鬼东西,然而在Action中出错的话,默认就返回了这个input了,这时,我们在struts的<result>中定义的话,就出现No result defined for action and result input的错误了。
引起这个错误的原因是很多的,路径错误也是其中的一种,我这里的问题是,我的页面上的类型和我定义的属性的类型不一致,我的属性是int型的,但是在页面上输出的时候加了一个逗号,用了分割千位的,结果就出现了这个问题了。
怎么办。 );
解决方法:1)、要么在struts.xml中配置一个<result type="input">;
2)、修改自定义的login的拦截器里面的return Action.INPUT;为你登录失败的type.比如:return Action.ERROR;或者return Action.LOGIN;
参见: http://ljt.me/?p=282
Convention插件自动注册Action的功能让我们从struts.xml配置的繁杂工作中解放出来,但有时候也能带来一些麻烦。出现”No result defined for action”错误就是其中之一。
比如我们在struts.xml中定义了一个名为logout的action,…action.LogoutAction是其实现类,这时Convention就会试图帮我们注册一个名叫logout的action,并搜索对应的jsp文件注册为result;如果xml文件和convention搜索出来的action重名,其缺省的原则是覆盖xml文件中的配置,这样我们原来在xml中定义的名为logout的action的result就没有了,于是出现了”No result defined for action”的错误。在我们不了解这个原则的时候一定很诧异:我明明定义了result,为什么报错说没有呢?其实就是被convention自动覆盖了。当我们知道了这个原则之后,就可以想办法避免了,首先xml定义action名字的时候避免和convention映射生成的action名字重复(需先了解convention的映射原则),convention是机械化的映射,而我们在xml文件中配置的aciton名字是可以根据需要进行修改的;其次如果可以的话,按convention的命名要求定义好jsp文件放到convention的result搜索路径中,这样convention就会自动注册result,不会再出现本文标题所示的错误了。多说一句,如何查看convention注册的action呢?答案是:struts2-config-browser-plugin,安装很简单,只需要复制到WEB-INF/lib中即可,使用也很简单,访问项目路径的/config-browser/子目录即可,当然了,这个插件并不是为convention设计的,它能显示所有在struts中注册的action,无论是否由convention注册。
和jsp中的 <form action="aaaaa" 改成<form action="Aaaaa"