这是我的jsp页面
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<!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>welcome</title>
</head>
<body> <s:form action="init" method="post">
<s:textfield name="username" label="用户名"></s:textfield>
<s:textfield name="password" label="密码"></s:textfield>
<s:textfield name="caption" label="书名"></s:textfield>
<s:textfield name="content" label="内容"></s:textfield>
<s:submit value="提交"></s:submit>
</s:form>
</body>
</html>这是我的Struts.xml
<struts> <package name="init" extends="struts-default">
<action name="init" class="com.cts.elt.SubmitAction">
<result name="success">/form.jsp</result> </action>
</package>
</struts>这是我的Action
public String execute() throws Exception {
InfoService infoservice = new InfoServiceImpl();
info.setCaption(caption);
info.setContent(content);
info.setPassword(password);
info.setUserName(userName); infoservice.addInfo(info);
return SUCCESS;
}我在地址栏里打了http://localhost:8080/StrutsHibernate.form.jsp,跳出了JSP页面。但是输入信息点了提交。
报错404:message There is no Action mapped for namespace [/] and action name [init] associated with context path [/StrutsHibernate].description The requested resource (There is no Action mapped for namespace [/] and action name [init] associated with context path [/StrutsHibernate].) is not available.明明Action名字什么都匹配了,为何还这样说?求大神指教菜鸟
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<!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>welcome</title>
</head>
<body> <s:form action="init" method="post">
<s:textfield name="username" label="用户名"></s:textfield>
<s:textfield name="password" label="密码"></s:textfield>
<s:textfield name="caption" label="书名"></s:textfield>
<s:textfield name="content" label="内容"></s:textfield>
<s:submit value="提交"></s:submit>
</s:form>
</body>
</html>这是我的Struts.xml
<struts> <package name="init" extends="struts-default">
<action name="init" class="com.cts.elt.SubmitAction">
<result name="success">/form.jsp</result> </action>
</package>
</struts>这是我的Action
public String execute() throws Exception {
InfoService infoservice = new InfoServiceImpl();
info.setCaption(caption);
info.setContent(content);
info.setPassword(password);
info.setUserName(userName); infoservice.addInfo(info);
return SUCCESS;
}我在地址栏里打了http://localhost:8080/StrutsHibernate.form.jsp,跳出了JSP页面。但是输入信息点了提交。
报错404:message There is no Action mapped for namespace [/] and action name [init] associated with context path [/StrutsHibernate].description The requested resource (There is no Action mapped for namespace [/] and action name [init] associated with context path [/StrutsHibernate].) is not available.明明Action名字什么都匹配了,为何还这样说?求大神指教菜鸟
解决方案 »
- 分页对struts2标签中的if不太清楚!求助。。谢谢
- 请问大家,我该不该去北大青鸟
- hibernate+struts结合开发的问题,插入数据没有问题,但是不能插入提交的数据
- 急,求高手解决100分
- 如何配置jsp环境的虚拟站点而不是目录,tomcat行吗?
- 寻求高手指导!
- 高手帮忙亚。一个Applet问题
- youhony 郑重通告:万众瞩目,CSDN第一火爆大帖诞生!众多高手,激情前往思考于极限之间!JAVA,PB,VC,C++,BCB,DEPHI各版期待英雄出现
- 用JDBC取NOTES中NSF数据库中数据遇到的问题
- 开发购买笔记本,个人四分之一,有工作年限合同,否则按比例补上,想买款合适的,请各位懂行的推荐,谢谢
- tomcat很有规律的崩溃
- 急!!!求助
还是其他的什么东西这个能直接访问吗?
http://localhost:8080/StrutsHibernate/init.do或者http://localhost:8080/StrutsHibernate/init.action
<struts>
<package name="init" extends="struts-default">
<action name="init" class="com.cts.elt.SubmitAction">
<result name="success">/form.jsp</result>
</action>
</package>
</struts>
你直接访问action,然后action会将请求转发到form.jsp页面的,试试下面这样。
http://localhost:8080/StrutsHibernate/init.action
红色部分是根据你的配置来写的,如果没有配置,默认就是.action你页面的代码<s:form action="<%=request.getContentPath %>/init.action" method="post">
<s:textfield name="username" label="用户名"></s:textfield>
<s:textfield name="password" label="密码"></s:textfield>
<s:textfield name="caption" label="书名"></s:textfield>
<s:textfield name="content" label="内容"></s:textfield>
<s:submit value="提交"></s:submit>
</s:form>
我访问http://localhost:8080/StrutsHibernate/init.action 还是出现404错误。
我访问http://localhost:8080/StrutsHibernate/init.action 还是出现404错误。这是什么原因呢?
你试一下改成这个:
<s:form action="init.action" method="post">
<action name="init" class="com.cts.elt.SubmitAction">
<result name="success">/form.jsp</result></action>
</package>
这里既然用到了包,就给个路径吧<package name="init" namespace="/init" extends="struts-default">
<action name="submitinit" class="com.cts.elt.SubmitAction">
<result name="success">/form.jsp</result>
</action>
</package>如果StrutsHibernate是你的项目名称,
地址栏输入:http://localhost:8080/StrutsHibernate/init/submitinit
看看效果。
<form action="<%=request.getContextPath()%>/init.action" method="post">
或者:
<form action="<%=request.getContextPath()%>/init.do" method="post">再不对就是其他问题,得慢慢debug了
哎 还是不行,我觉得不是配置的问题,会不会是web.xml没写好 或者别的可能?
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.FilterDispatcher
</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
我是这样配置的
<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>*.action</url-pattern>
</filter-mapping>
InfoService infoservice = new InfoServiceImpl();
info.setCaption(caption);
info.setContent(content);
info.setPassword(password);
info.setUserName(userName);infoservice.addInfo(info);
return new ActionForward("/form.jsp");
}
那要是这样还报错吗~?????
InfoService infoservice = new InfoServiceImpl();
info.setCaption(caption);
info.setContent(content);
info.setPassword(password);
info.setUserName(userName);infoservice.addInfo(info);
return new ActionForward("/form.jsp");
}
那要是这样还报错吗~?????
<action name="init" class="com.cts.elt.SubmitAction">
<result name="success">/form.jsp</result></action>
</package>
这里不要/ 直接写成form.jsp 试试
恩恩 改了以后404错误解决了 现在报了500空指针异常。
public String execute() throws Exception {
System.out.println("into Action1111111111111");
InfoService infoservice = new InfoServiceImpl();
info.setCaption(caption);
info.setContent(content);
info.setPassword(password);
info.setUserName(username);
System.out.println("Action==========" + info.getPassword()
+ info.getUserName());
infoservice.addInfo(info);
return SUCCESS;
我在Action里面输入System.out.println("into Action1111111111111")调试,控制台没有打印出这句话,就说明没有进这个方法,这是为什么呢?;
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
"<filter-class>"你原来怎么写就怎么写,我的那个class只是个例子
你之前写的这个:org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
那就用这个。