大家帮我看看下面这个Struts练习哪儿错了?为什么达不到效果?
资料说点击链接,能赚到Hello.jsp上面,可是我点击链接,提示找不到hello.aciton.
这个是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="com.wq" extends="struts-default" namespace="/"> <action name="hello"> <result>/hello.jsp</result> </action> </package> </struts>
index.jsp
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>struts hello world</title> </head> <body> <a href="hello.action">问好</a> </body> </html>
Hello.jsp
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>你好</title> </head> <body> Hello world! </body> </html>
贴出来你的web.xml 看看!
你还需要写一个hello对应的class,并return “success”
[code="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">
/hello.jsp
[/code]
如果没有为action指定class,默认是ActionSupport类 相当于
如果没有为action指定method,默认执行action中的execute()方法相当于如果
没有指定result的name属性,默认值为success.相当于
路上的回答 不正确哟
你的action个配置错了,需要指定一个class类
问好 把.action去掉或者是你看看配置常量后缀名为.do了吗
楼上几位的回答 貌似都没理解struts的机制。楼主的配置及页面都没啥问题,目测是访问url的问题 找不到hello.action 肯定是namespace与url没有对上
很奇怪的说法。为什么struts要不指定类呢?假如在实际开发中,这根本不可行..
struts.xml放在WEB-INF/classes目录下, web.xml里的初始化参数加上该文件名
[code="xml"]
struts
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
config
struts-default.xml,[color=red]struts.xml[/color]
[/code]
我觉得是路径问题