action代码public class MeetingAction extends DispatchAction { public ActionForward intoIndex(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
TimeConversion tc = new TimeConversion();
String dateNow = tc.getDateNow();
String num = "";
switch (tc.getDayOfWeekNow()) {
case 1:
num = "一";
break;
case 2:
num = "二";
break;
case 3:
num = "三";
break;
case 4:
num = "四";
break;
case 5:
num = "五";
break;
}
String weekNow = "每周" + num;
MeetingDAO mdao = DAOFactory.getMeetingDAOInstants();
List<MeetingVO> all = null;
try {
all = mdao.listMeetingForDate(dateNow, weekNow);
} catch (Exception e) {
LogBean.logger.error(e.getMessage());
}
request.setAttribute("list", all);
return mapping.findForward("index");
}
}配置文件<action
attribute="meetingForm"
input="/meeting/index.jsp"
name="meetingForm"
parameter="action"
path="/meeting/index"
scope="request"
type="com.anyka.meeting.action.MeetingAction">
<forward name="index" path="/meeting/index.jsp" />
</action>跳转url:http://XX/meeting/index.do?action=intoIndex
报错严重: Servlet.service() for servlet action threw exception
javax.servlet.ServletException: Request[/meeting/index] does not contain handler parameter named 'action'. This may be caused by whitespace in the label text.
at org.apache.struts.actions.DispatchAction.unspecified(DispatchAction.java:215)
at org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:249)
at org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:187)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.anyka.filter.EncodingFilter.doFilter(Unknown Source)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:619)
哪位可以告诉我到底是为什么。。我是直接在地址栏里打上url,没有经过表单提交。。
HttpServletRequest request, HttpServletResponse response) {
TimeConversion tc = new TimeConversion();
String dateNow = tc.getDateNow();
String num = "";
switch (tc.getDayOfWeekNow()) {
case 1:
num = "一";
break;
case 2:
num = "二";
break;
case 3:
num = "三";
break;
case 4:
num = "四";
break;
case 5:
num = "五";
break;
}
String weekNow = "每周" + num;
MeetingDAO mdao = DAOFactory.getMeetingDAOInstants();
List<MeetingVO> all = null;
try {
all = mdao.listMeetingForDate(dateNow, weekNow);
} catch (Exception e) {
LogBean.logger.error(e.getMessage());
}
request.setAttribute("list", all);
return mapping.findForward("index");
}
}配置文件<action
attribute="meetingForm"
input="/meeting/index.jsp"
name="meetingForm"
parameter="action"
path="/meeting/index"
scope="request"
type="com.anyka.meeting.action.MeetingAction">
<forward name="index" path="/meeting/index.jsp" />
</action>跳转url:http://XX/meeting/index.do?action=intoIndex
报错严重: Servlet.service() for servlet action threw exception
javax.servlet.ServletException: Request[/meeting/index] does not contain handler parameter named 'action'. This may be caused by whitespace in the label text.
at org.apache.struts.actions.DispatchAction.unspecified(DispatchAction.java:215)
at org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:249)
at org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:187)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.anyka.filter.EncodingFilter.doFilter(Unknown Source)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:619)
哪位可以告诉我到底是为什么。。我是直接在地址栏里打上url,没有经过表单提交。。
不能正确执行需要执行的方法
也就是缺少action=方法名这个东西
这个是我的url。是什么问题呢?
这个parameter应该不是指的封装request里面的参数
你自己从request中获取 action参数 试试
super.setServlet(actionServlet);
}
我怎么记得是 method=“action”
才是这样调用的 index.do?action=intoIndex
parameter 改 method试试
楼主,你两个地方都改了么?
struts.xml里面 parameter="action"改为 parameter="method"
url你改为:http://XX/meeting/index.do?method=intoIndex
有区别么。。方法名只是个名字我用abcd一样可以。配置文件的东西。。不要那么死板。。别人method你就全部method没用的
①attribute="TargetSearchForm"
name="TargetSearchForm"
parameter="action"path="/TargetSearch"
scope="request"
type="com.monitor.action.targetstore.TargetSearchAction"
URL:http://127.0.0.1:8080/TargetSearch.do?action=toTargetSearchTop
报和你一样的错。
②attribute="TargetSearchForm"
name="TargetSearchForm"
parameter="bbb"path="/TargetSearch"
scope="request"
type="com.monitor.action.targetstore.TargetSearchAction"
URL:http://127.0.0.1:8080/TargetSearch.do?bbb=toTargetSearchTop
页面跳转正常。
这两个例子说明什么?说明action是个关键字,struts的API在解析URL时出错了。有兴趣可以去看下struts的源码,看看它是怎么解析URL的。哎,无语啊,对LZ的固执很感慨。
说明,action是个
①attribute="TargetSearchForm"
name="TargetSearchForm"
parameter="action"
path="/TargetSearch"
scope="request"
type="com.monitor.action.targetstore.TargetSearchAction"
URL:http://127.0.0.1:8080/TargetSearch.do?action=toTargetSearchTop
报和你一样的错。
②attribute="TargetSearchForm"
name="TargetSearchForm"
parameter="bbb"
path="/TargetSearch"
scope="request"
type="com.monitor.action.targetstore.TargetSearchAction"
URL:http://127.0.0.1:8080/TargetSearch.do?bbb=toTargetSearchTop
页面跳转正常。
这两个例子说明什么?说明action是个关键字,struts的API在解析URL时出错了。有兴趣可以去看下struts的源码,看看它是怎么解析URL的。哎,无语啊,对LZ的固执很感慨。楼主,你创新可以,但是不能盲目自信呀。
我写这个新系统才出现这样的错误的。。以前的系统全是这样写的没有问题。。
哦还有我问题解决了......呵呵。唉....不是我固执是你没了解到关键的地方。。而且这个也不是我创新。。谁说parameter的配置属性一定要method.....?
Action是关键词 并不是说 全要用成Method 这仅仅是一个参数名而已,但不要用关键字
LZ还是虚心点好
也就是说,你的请求参数需要包含action=intoIndex,才会正确执行
何况我现在已经把问题解决..我的parameter参数依然是action
action什么时候成关键字了
我以前的项目也都是用action没报过错
你不要在地址栏打URL了
用form提交试试注意加上 method="post"
配置应该是没有错的
哦还有一会我会和大家分享讨论下这个问题是怎么解决的
一样可以设置method="post"document.forms[0].action="http://XX/meeting/index.do?action=intoIndex";
document.forms[0].method="post";
document.forms[0].submit();
http://XX/meeting/index.do?method=intoIndex
对应struts-config
parameter="method"
http://XX/meeting/index.do?action=intoIndex后来错误解决是因为我发现dispatchAction有一个默认的action方法unspecified()这个方法是在你没有指定其他方法时他会默认跳转到这个方法。
可能是因为我不是表单提交没有指定method="post"所以导致解析错误
但是加入了unspecified()这个方法以后就不会存在这个问题了。
--------------------------------------------------------------------------------------------
可能我的理解还是有错误,如果有大虾能指出这个问题的关键原因小弟感激不尽....加满100分送您
所以导致了dispatchMethod找不到相应的执行方法,因此调用unspecified方法。而这个方法的默认实现就是Exception。你实现了一个,就是什么也不报错,但是并不是你要的,执行intoIndex方法。所以,你还是要检查你的request参数
不仅仅是不报错。因为我写得unspecified方法是空方法。执行的的确是intoIndex方法
打断点试试看看进去没
调用unspecified方法会抛出异常自动跳转至input的属性
input="/meeting/index.jsp"
跳转的这个页面和你执行intoIndex方法跳转的页面一样
刚才研究了下struts的代码,发现出现直接打URL请求出异常的原因为:
以楼主的URL为例子,http://XX/meeting/index.do?action=intoIndex
是执行完intoIndex方法之后,会返回一个Forward,此返回的Forward是会以doPost方式执行。所以request中没有发现action这个参数。
Struts源码中出现如下判断:public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
if (isCancelled(request)) {
ActionForward af = cancelled(mapping, form, request, response); if (af != null) {
return af;
}
} // Get the parameter. This could be overridden in subclasses.
String parameter = getParameter(mapping, form, request, response); // Get the method's name. This could be overridden in subclasses.
String name =
getMethodName(mapping, form, request, response, parameter); // Prevent recursive calls
if ("execute".equals(name) || "perform".equals(name)) {
String message =
messages.getMessage("dispatch.recursive", mapping.getPath()); log.error(message);
throw new ServletException(message);
} // Invoke the named method, and return the result
return dispatchMethod(mapping, form, request, response, name);
}
protected ActionForward dispatchMethod(ActionMapping mapping,
ActionForm form, HttpServletRequest request,
HttpServletResponse response, String name)
throws Exception {
// Make sure we have a valid method name to call.
// This may be null if the user hacks the query string.
if (name == null) {
return this.unspecified(mapping, form, request, response);
}
。
。
。谢谢楼主让我保持清醒,呵呵
intoIndex执行以后页面才会显示数据
------------------------------------------------------------------------------------------------
而url直接提交现在还是个谜,现在更奇怪的事情出现了。运行成功以后即使我删除unspecified方法,程序依然正常执行,无错误
-----------------------------------------------------------------------------------------------
at org.apache.struts.actions.DispatchAction.unspecified(DispatchAction.java:215)
at org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:249)
at org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:187)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)
你没写unspecified时不行,写了就好了,然后删掉也好了。看来是缓存问题呀。另:parameter=action没什么问题,从request.getParameter("action")中取的值。
如果没配parameter或配了但传的参数是null,都报servlet exception;但如果配了传的参数指定的方法不存在,报的是nosuchmethod exception.