★struts2 The requested resource (/tutorial/HelloWorld.action) is not available 是怎么回事?★
web.xml<?xmlversion="1.0"encoding="UTF-8"?><web-appversion="2.5"xmlns="http://java.su...
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
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_2_5.xsd">
<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>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
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>
<!--
<constant name="struts.enable.DynamicMethodInvocation" value="false" />
<constant name="struts.devMode" value="false" />
s
<package name="default" namespace="/" extends="struts-default">
<default-action-ref name="index" />
<action name="HelloWorld" class="/HelloWorldAction">
<result">
/HelloWorld.jsp
</result>
</action>
</package>
-->
</struts>
HelloWorldAction.java
import java.util.*;
import java.text.DateFormat;
import com.opensymphony.xwork2.ActionSupport;
public class HelloWorldAction extends ActionSupport {
private String message;
public String getMessage() {
return message;
}
public void setMessage() {
message = "";
}
public String execute() {
message="HelloWorld,Now is"
+ DateFormat.getDateInstance().format(new Date());
return "SUCCESS";
}
}
HelloWorld.jsp
<%@ page language="java" pageEncoding="GBK"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
<title>HelloWorld!</title>
</head>
<body>
<h2>
<s:property value="message"/>
</h2>
</body>
</html> 展开
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
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_2_5.xsd">
<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>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
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>
<!--
<constant name="struts.enable.DynamicMethodInvocation" value="false" />
<constant name="struts.devMode" value="false" />
s
<package name="default" namespace="/" extends="struts-default">
<default-action-ref name="index" />
<action name="HelloWorld" class="/HelloWorldAction">
<result">
/HelloWorld.jsp
</result>
</action>
</package>
-->
</struts>
HelloWorldAction.java
import java.util.*;
import java.text.DateFormat;
import com.opensymphony.xwork2.ActionSupport;
public class HelloWorldAction extends ActionSupport {
private String message;
public String getMessage() {
return message;
}
public void setMessage() {
message = "";
}
public String execute() {
message="HelloWorld,Now is"
+ DateFormat.getDateInstance().format(new Date());
return "SUCCESS";
}
}
HelloWorld.jsp
<%@ page language="java" pageEncoding="GBK"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
<title>HelloWorld!</title>
</head>
<body>
<h2>
<s:property value="message"/>
</h2>
</body>
</html> 展开
4个回答
展开全部
struts配置里:
<package name="default" namespace="/" extends="struts-default">
<action name="HelloWorld" class="HelloWorldAction">
<result name="success">/HelloWorld.jsp</result>
</action>
</package>
Action函数里:
public String execute() {
message="HelloWorld,Now is"
+ DateFormat.getDateInstance().format(new Date());
return SUCCESS;(此处没有引号)
}
页面调用时 <s:form action="HelloWorld" method="post">
<package name="default" namespace="/" extends="struts-default">
<action name="HelloWorld" class="HelloWorldAction">
<result name="success">/HelloWorld.jsp</result>
</action>
</package>
Action函数里:
public String execute() {
message="HelloWorld,Now is"
+ DateFormat.getDateInstance().format(new Date());
return SUCCESS;(此处没有引号)
}
页面调用时 <s:form action="HelloWorld" method="post">
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
<action name="HelloWorld" class="/HelloWorldAction">
<result">
不需要“/",也多了一个“"”
tutorial是你的项目名字吗?如果不是也会出错误的
<result">
不需要“/",也多了一个“"”
tutorial是你的项目名字吗?如果不是也会出错误的
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
<result"> 多了个引号
<action name="HelloWorld" class="/HelloWorldAction">class 不用加/
<action name="HelloWorld" class="/HelloWorldAction">class 不用加/
追问
我试了,还是不行啊!!
追答
s
/HelloWorld.jsp
-->
以上都注释起来了怎么还能行 中间还多了个 s
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
class="/HelloWorldAction" 后面的class要带包名。
更多追问追答
追问
默认的,,没有包
追答
不带包名肯定会报404错误。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询