没有映射名称空间[/]的动作和与上下文路径[/ TestStruts]相关联的动作名称[Test]。(There is no Action mapped for namespace [/] and action name [Test] associated with context path [/TestStruts]. - [unknown location])
我正在NetBeans 7.2.1中尝试我的第一个应用程序struts 2.3.16。 它在输入URL时显示以下错误 -
http://localhost:8080/TestStruts/Test.action
(有一个Test.jsp
页面)。WARNING: Could not find action or result: /TestStruts/Test.action There is no Action mapped for namespace [/] and action name [Test] associated with context path [/TestStruts]. - [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:37) at com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:58) at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:552) at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77) at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:99) 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:222) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936) 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:1004) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589) at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:1822) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603) at java.lang.Thread.run(Thread.java:722)
Test.jsp
页面:<s:form namespace="/TestStruts" action="test"> <table border="0" class=""> <tr> <td> <s:textfield id="name" name="name" label="Enter your name"/> </td> </tr> <tr> <td> <s:textfield id="email" name="email" label="Enter your email"/> </td> </tr> <tr> <td></td> <td><s:submit value="Submit"/></td> </tr> </table> </s:form>
动作类:
package actions; import com.opensymphony.xwork2.ActionSupport; public final class TestAction extends ActionSupport { private static final String SUCCESS = "success"; private String name; private String email; public String getName() { return name; } public void setName(String name) { this.name = name; } public String getEmail() { return email; } public void setEmail(String email) { this.email = email; } @Override public String execute() throws Exception { System.out.println("name = "+name); System.out.println("email = "+email); return SUCCESS; } }
strtus.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> <constant name="struts.enable.DynamicMethodInvocation" value="false" /> <constant name="struts.devMode" value="true" /> <constant name="struts.custom.i18n.resources" value="myapp" /> <package name="test" namespace="/TestStruts" extends="struts-default"> <action name="test" class="actions.TestAction" method="execute"> <result name="success">/Test.jsp</result> </action> </package> </struts>
web.xml
文件:<?xml version="1.0" encoding="UTF-8"?> <web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"> <context-param> <param-name>contextConfigLocation</param-name> <param-value> /WEB-INF/applicationContext.xml </param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <filter> <filter-name>struts2</filter-name> <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <session-config> <session-timeout> 30 </session-timeout> </session-config> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> </web-app>
除了Spring的jar文件之外,我还将以下jar文件添加到了类路径中。
- 公地的BeanUtils-1.8.0.jar
- 公共链1.2.jar
- 公地集合-3.1.jar
- 公共沼气池-2.0.jar
- 公地文件上传-1.3.jar
- 公地IO-2.2.jar
- 公地lang3-3.1.jar
- 公地郎2.4.jar
- 共享记录-1.1.3.jar
- 共享记录-API-1.1.jar
- 公地验证-1.3.1.jar
- freemarker的-2.3.19.jar
- Javassist进行-3.11.0.GA.jar
- OGNL-3.0.6.jar
- Struts2的核心 - 2.3.16.jar
- struts2的 - 弹簧 - 插件-2.3.16.jar
- XWork的核心,2.3.16.jar
当URL从
.action
例如http://localhost:8080/TestStruts/Test.jsp
)更改为.jsp
,它会显示以下警告。Dec 22, 2013 9:00:44 PM org.apache.struts2.components.ServletUrlRenderer warn WARNING: No configuration found for the specified action: 'test' in namespace: '/TestStruts'. Form action defaulting to 'action' attribute's literal value. Dec 22, 2013 9:00:45 PM org.apache.struts2.components.ServletUrlRenderer warn WARNING: No configuration found for the specified action: 'test' in namespace: '/TestStruts'. Form action defaulting to 'action' attribute's literal value.
我错过了什么?
I'm trying my first application on struts 2.3.16 in NetBeans 7.2.1. It shows the following error on entering a URL -
http://localhost:8080/TestStruts/Test.action
(There is aTest.jsp
page).WARNING: Could not find action or result: /TestStruts/Test.action There is no Action mapped for namespace [/] and action name [Test] associated with context path [/TestStruts]. - [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:37) at com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:58) at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:552) at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77) at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:99) 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:222) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936) 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:1004) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589) at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:1822) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603) at java.lang.Thread.run(Thread.java:722)
The
Test.jsp
page:<s:form namespace="/TestStruts" action="test"> <table border="0" class=""> <tr> <td> <s:textfield id="name" name="name" label="Enter your name"/> </td> </tr> <tr> <td> <s:textfield id="email" name="email" label="Enter your email"/> </td> </tr> <tr> <td></td> <td><s:submit value="Submit"/></td> </tr> </table> </s:form>
The action class:
package actions; import com.opensymphony.xwork2.ActionSupport; public final class TestAction extends ActionSupport { private static final String SUCCESS = "success"; private String name; private String email; public String getName() { return name; } public void setName(String name) { this.name = name; } public String getEmail() { return email; } public void setEmail(String email) { this.email = email; } @Override public String execute() throws Exception { System.out.println("name = "+name); System.out.println("email = "+email); return SUCCESS; } }
The
strtus.xml
file:<?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> <constant name="struts.enable.DynamicMethodInvocation" value="false" /> <constant name="struts.devMode" value="true" /> <constant name="struts.custom.i18n.resources" value="myapp" /> <package name="test" namespace="/TestStruts" extends="struts-default"> <action name="test" class="actions.TestAction" method="execute"> <result name="success">/Test.jsp</result> </action> </package> </struts>
The
web.xml
file:<?xml version="1.0" encoding="UTF-8"?> <web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"> <context-param> <param-name>contextConfigLocation</param-name> <param-value> /WEB-INF/applicationContext.xml </param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <filter> <filter-name>struts2</filter-name> <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <session-config> <session-timeout> 30 </session-timeout> </session-config> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> </web-app>
In addition to jar files of Spring, I have added the following jar files to the classpath.
- commons-beanutils-1.8.0.jar
- commons-chain-1.2.jar
- commons-collections-3.1.jar
- commons-digester-2.0.jar
- commons-fileupload-1.3.jar
- commons-io-2.2.jar
- commons-lang3-3.1.jar
- commons-lang-2.4.jar
- commons-logging-1.1.3.jar
- commons-logging-api-1.1.jar
- commons-validator-1.3.1.jar
- freemarker-2.3.19.jar
- javassist-3.11.0.GA.jar
- ognl-3.0.6.jar
- struts2-core-2.3.16.jar
- struts2-spring-plugin-2.3.16.jar
- xwork-core-2.3.16.jar
When the URL is changed to
.jsp
from.action
likehttp://localhost:8080/TestStruts/Test.jsp
, it shows the following warnings.Dec 22, 2013 9:00:44 PM org.apache.struts2.components.ServletUrlRenderer warn WARNING: No configuration found for the specified action: 'test' in namespace: '/TestStruts'. Form action defaulting to 'action' attribute's literal value. Dec 22, 2013 9:00:45 PM org.apache.struts2.components.ServletUrlRenderer warn WARNING: No configuration found for the specified action: 'test' in namespace: '/TestStruts'. Form action defaulting to 'action' attribute's literal value.
What am I missing?
原文:https://stackoverflow.com/questions/20730967
最满意答案
- 使用块形式
gsub(regex){ $1 }
而不是gsub(regex, '\1')
- 您也可以将正则表达式简化为
/\B#(\w+)/i
- 您可以省略
h()
帮助程序,Rails 4默认会转义恶意输入- 将方法参数指定为
embed_hashtag(data)
而不是embed_hashtag('data')
- 在进行替换之前,您需要定义
embed_hashtag
- 要建立一个链接,你可以使用
link_to(text, url)
这应该可以做到这一点:
def embed_hashtag(tag) url = 'http://example.com' link_to tag, url end raw( text.gsub(/\B#(\w+)/i){ embed_hashtag($1) } )
- Use the block form
gsub(regex){ $1 }
instead ofgsub(regex, '\1')
- You can simplify the regex to
/\B#(\w+)/i
as well- You can leave out the
h()
helper, Rails 4 will escape malicious input by default- Specify method arguments as
embed_hashtag(data)
instead ofembed_hashtag('data')
- You need to define
embed_hashtag
before doing the substitution- To build a link, you can use
link_to(text, url)
This should do the trick:
def embed_hashtag(tag) url = 'http://example.com' link_to tag, url end raw( text.gsub(/\B#(\w+)/i){ embed_hashtag($1) } )
相关问答
更多-
通常,不要在ERB中使用多行语句。 把它分成两行。 并使用gsub! 更改render对象。 <% replacements = [ ['data-imgslap=', 'src='], ['src="http://i.imgur.com/bEDR9dc.png"', ''] ] %> <% replacements.each {|replacement| render.gsub!(replacement[0], replacement[1])} %> <%= render.html_safe %> ...
-
也许你可以使用#split而不是正则表达式? "This is a tweet with an image. http://twitpic.com/12345".split("http://twitpic.com/")[1] Maybe you can use #split instead of a regex? "This is a tweet with an image. http://twitpic.com/12345".split("http://twitpic.com/")[1]
-
在方法中调用gsub(Calling gsub within method)[2023-05-22]
像string.delete_commas一样定义String类的方法, delete_commas应该是String方法 class String def delete_commas self.gsub(',','') end end string = "this string, has, alot, of, commas,,," string.delete_commas # => "this string has alot of commas" Define a method ... -
你在混合一些完全不同的概念,你应该在尝试完成这个任务之前直接获得基础知识。 要在请求之间传递变量,您可以使用参数。 这可以是URL段,查询字符串或请求主体(通过使用表单)的形式。 由于服务器上的变量不会在请求之间持续存在,因此您无法将局部变量传递给link_to ,我不知道您从哪里获得了可以工作的概念。 https://www.codecademy.com/articles/request-response-cycle-dynamic http://guides.rubyonrails.org/routin ...
-
使用块形式gsub(regex){ $1 }而不是gsub(regex, '\1') 您也可以将正则表达式简化为/\B#(\w+)/i 您可以省略h()帮助程序,Rails 4默认会转义恶意输入 将方法参数指定为embed_hashtag(data)而不是embed_hashtag('data') 在进行替换之前,您需要定义embed_hashtag 要建立一个链接,你可以使用link_to(text, url) 这应该可以做到这一点: def embed_hashtag(tag) url = 'htt ...
-
这应该做的伎俩,因为root_url(和root_path)没有参数: <%= link_to @user.username, root_url %> This should do the trick, as root_url (and root_path) do not have parameters: <%= link_to @user.username, root_url %>
-
Rails - 在helper方法中使用gsub时的void值表达式(Rails - void value expression when using gsub in helper method)[2023-05-30]
break是Ruby中的保留关键字,在其实现中定义,您可以在其他文件中查看此文件 : struct kwtable; %% __ENCODING__, {keyword__ENCODING__, keyword__ENCODING__}, EXPR_END __LINE__, {keyword__LINE__, keyword__LINE__}, EXPR_END __FILE__, {keyword__FILE__, keyword__FILE__}, EXPR_END BEGIN, {keyword_B ... -
如果你需要删除字符,你可以使用#delete str.delete "[]^()#*?~" If you need to remove characters you can use #delete str.delete "[]^()#*?~"
-
你可能没有emp_id 。 尝试将代码更改为, <% @last_emp_id = EmployeeDetail.select("employee_id").last %> <% emp_id = @last_emp_id.employee_id %> <% emp_id_sub = emp_id.present? ? emp_id.gsub(/[^\d]/, '') : ''%> <% auto_generate_id = emp_id_sub.length > 0 ? ? ('E'.to_s + (e ...
-
Ruby:如何在字符串插值内的符号上使用gsub方法#{}(Ruby: how to use gsub method on symbol inside string interpolation #{})[2022-10-02]
确实,在字符串插值中, 单个符号将被字符串化。 >> s = :hello => :hello >> "#{s}" => "hello" 但是你必须记住,括号内的整个表达式在字符串化之前都要进行评估。 这就是为什么你看到: >> "#{s.gsub('u','e')}" NoMethodError: undefined method `gsub' for :hello:Symbol from (irb):3 from /usr/local/bin/irb:11:in `' 所 ...