该问题已解决,链接地址:http://wlzjdm.iteye.com/blog/1521105
最近刚刚学完注解,就练习了一下下。我采用的是jsp页面里面的javascript代码访问action……
但是,我配置的注解无法将url和action进行映射,而且其中还出现了一个问题……
先看看我的那个jsp页面信息:
位置:WebRoot
内容:
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
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>
<title>My JSP 'ajaxAndStruts2.jsp' starting page</title>
<script type="text/javascript" src="../javascript/jquery-1.7.1.js"></script>
<script type="text/javascript">
$(function() {
$("#ok").click(function() {
$.post("./getLover.action",{"name":$("#name").val()},function(data){
},"xml");
});
});
</script>
<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>
<input type="text" id="name">
<input type="button" id="ok" value="select">
</body>
</html>
那么对应的Action的注解配置极其类内容为:
package com.dong.struts2WithOthers;
import org.apache.struts2.convention.annotation.Action;
import com.dong.util.Lover;
import com.opensymphony.xwork2.ActionSupport;
@Action(value = "getLover")
public class ByAjaxTest extends ActionSupport
{
private String name;
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
@Override
public String execute() throws Exception
{
System.out.println("hello");
System.out.println(name);
if(name == "dongdong")
{
Lover lover = new Lover("xiaojing",21,"girl");
}
return "none";
}
}
出现的错误信息
2012-5-8 17:58:01 com.opensymphony.xwork2.util.logging.commons.CommonsLogger warn
警告: Could not find action or result
There is no Action mapped for namespace [/] and action name [getLover] associated with context path [/struts2]. - [unknown location]
at com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:185)
at org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:63)
at org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:39)
at com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:58)
at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:500)
at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:987)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:579)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:309)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:619)
我的分析与猜想:
我写的这个Action处理类是新建了一个包com.dong.struts2WithOthers;(原来练习的时候,所有的action都位于com.dong.action;这个包下面),当我吧这个类移动到原来的包下面的时候,可以正常运行,但是为何在新的包中就无法运行呢了。
我想这个是命名空间的问题,但是吧,尝试了好多次,都没有解决。不知道该如何的设定命名空间。
请求朋友指教帮忙。
我不明白为何提交请求后,它会自动的去com.dong.action;(原来练习struts2的包)中去找对应的Action
注:源代码并未完全实现我的目标,只是在进行链接测试的时候,遇到了问题,就停滞了下来。。。
分享到:
相关推荐
标题 "http://topkinghat.iteye.com/blog/840706" 提到的博客链接实际上指向了“姜铁”的个人博客文章,而描述中的 "NULL" 暂无具体信息。不过,标签“源码”和“工具”暗示了这篇博客可能涉及到软件开发的源代码...
博文链接:https://jackzhangyunjie.iteye.com/blog/202349
NULL 博文链接:https://wy649898543.iteye.com/blog/1423655
jstl和Struts和Jsp 博文链接:https://weiye.iteye.com/blog/36834
NULL 博文链接:https://ownraul.iteye.com/blog/1277047
http://www.iteye.com/topic/699515 主题:Swing是一把刀 http://www.iteye.com/topic/702804 主题:Swing第二刀:枝间新绿一重重 http://www.iteye.com/topic/707540 主题:Swing第二小刀刀:星星之火可以燎原 ...
博文链接:https://avery-leo.iteye.com/blog/213980
从零开始学Spring Boot,没有积分的可以看博客:http://412887952-qq-com.iteye.com/ 【Spring Boot 系列博客】 0)前言【从零开始学Spring Boot】 : http://412887952-qq-com.iteye.com/blog/2291496 (1...
NULL 博文链接:https://zw7534313.iteye.com/blog/426799
NULL 博文链接:https://jyao.iteye.com/blog/1235905
NULL 博文链接:https://ajita.iteye.com/blog/1725304
NULL 博文链接:https://yizhilong28.iteye.com/blog/1161027
NULL 博文链接:https://zzz299.iteye.com/blog/691049
NULL 博文链接:https://timewalker.iteye.com/blog/1065615
博文链接:https://wdfan.iteye.com/blog/197543
NULL 博文链接:https://wincheer.iteye.com/blog/774298
NULL 博文链接:https://qiusenvs.iteye.com/blog/412763
博文链接:https://balaschen.iteye.com/blog/82579
手机理财1.0.7 博文链接:https://iwinyeah.iteye.com/blog/213328