Struts2的简单配置问题
Jar包都有的。。请看完以下配置。。。action:publicclassFirstActionextendsActionSupport{/****/privatesta...
Jar包都有的。。请看完以下配置。。。
action:
public class FirstAction extends ActionSupport {
/**
*
*/
private static final long serialVersionUID = -8196749365964368556L;
private int num1;
private int num2;
@Override
public String execute() throws Exception {
if(getSum()>0){
return "positive";
}else{
return "negative";
}
}
public int getNum1() {
return num1;
}
public void setNum1(int num1) {
this.num1 = num1;
}
public int getNum2() {
return num2;
}
public void setNum2(int num2) {
this.num2 = num2;
}
private int getSum(){
return num1+num2;
}
}
struts.xml:
<struts>
<package name="struts2" extends="struts-default" namespace="/mystruts">
<action name="sum" class="com.yyh.struts2.action.FirstAction">
<result name="positive">/positive.jsp</result>
<result name="negative">/negative.jsp</result>
</action>
</package>
</struts>
web.xml:
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.FilterDispatcher
</filter-class>
</filter>
<!-- Struts的Filter的URI配置 -->
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
sum.jsp:
<s:form action="mystruts/sum.action">
<s:textfield name="num1" label="操作数1"/>
<s:textfield name="num2" label="操作数2"/>
<s:submit value="代数和"/>
</s:form>
我看配置应该都没有错,但访问这个页面报找不到action...:
警告: No configuration found for the specified action: 'mystruts/sum.action' in namespace: ''. Form action defaulting to 'action' attribute's literal value.
六月 05, 2012 9:04:00 上午 org.apache.struts2.components.Form evaluateExtraParamsServletRequest
如果提交的话:
HTTP Status 404 - There is no Action mapped for namespace /mystruts and action name sum.
type Status report
message There is no Action mapped for namespace /mystruts and action name sum.
description The requested resource (There is no Action mapped for namespace /mystruts and action name sum.) is not available.
求高人指点。。。 展开
action:
public class FirstAction extends ActionSupport {
/**
*
*/
private static final long serialVersionUID = -8196749365964368556L;
private int num1;
private int num2;
@Override
public String execute() throws Exception {
if(getSum()>0){
return "positive";
}else{
return "negative";
}
}
public int getNum1() {
return num1;
}
public void setNum1(int num1) {
this.num1 = num1;
}
public int getNum2() {
return num2;
}
public void setNum2(int num2) {
this.num2 = num2;
}
private int getSum(){
return num1+num2;
}
}
struts.xml:
<struts>
<package name="struts2" extends="struts-default" namespace="/mystruts">
<action name="sum" class="com.yyh.struts2.action.FirstAction">
<result name="positive">/positive.jsp</result>
<result name="negative">/negative.jsp</result>
</action>
</package>
</struts>
web.xml:
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.FilterDispatcher
</filter-class>
</filter>
<!-- Struts的Filter的URI配置 -->
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
sum.jsp:
<s:form action="mystruts/sum.action">
<s:textfield name="num1" label="操作数1"/>
<s:textfield name="num2" label="操作数2"/>
<s:submit value="代数和"/>
</s:form>
我看配置应该都没有错,但访问这个页面报找不到action...:
警告: No configuration found for the specified action: 'mystruts/sum.action' in namespace: ''. Form action defaulting to 'action' attribute's literal value.
六月 05, 2012 9:04:00 上午 org.apache.struts2.components.Form evaluateExtraParamsServletRequest
如果提交的话:
HTTP Status 404 - There is no Action mapped for namespace /mystruts and action name sum.
type Status report
message There is no Action mapped for namespace /mystruts and action name sum.
description The requested resource (There is no Action mapped for namespace /mystruts and action name sum.) is not available.
求高人指点。。。 展开
3个回答
展开全部
把配置文件的命名空间去掉试试,form里面的路径直接对应sum.action
更多追问追答
追问
没用,我试过。
追答
你不会是没有发布吧?还有JSP页面你用的是struts的标签,为什么不用传统的html标签试试呢?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
action="struts2!sum.action"
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你的web.Xml url-pattern 怎么写的 好像*.action
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询