HelloWorld.javapackage org.xmh.demo;import java.util.Date;
import java.text.DateFormat;
import com.opensymphony.xwork2.ActionSupport;public class HelloWorld extends ActionSupport {
private String message;
public String getMessage(){
return message;
}
public String execute(){
message="Hello World,Now is"+ DateFormat.getInstance().format(new Date());
return SUCCESS;
}}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="tutorial" extends="struts-default">
<action name="HelloWorld" class="org.xmh.demo.HelloWorld">
<result>/HelloWorld.jsp</result>
</action>
</package>
</struts>
HelloWorld.jsp<%@ page contentType="text/html"; charset="UTF-8" %>
<%@ taglib prefix="s" uri="/struts-tags" %><html>
<head>
<title>Hello World!</title> </head>
<body>
<h2>
<s:property value="message"/>
</h2>
</body>
</html>
Tomcat总是报404错误The requested resource (/HW/HelloWorld.action) is not available.
我现在找不出什么错误,是Tomcat还是代码问题,那位大大帮个忙啊
import java.text.DateFormat;
import com.opensymphony.xwork2.ActionSupport;public class HelloWorld extends ActionSupport {
private String message;
public String getMessage(){
return message;
}
public String execute(){
message="Hello World,Now is"+ DateFormat.getInstance().format(new Date());
return SUCCESS;
}}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="tutorial" extends="struts-default">
<action name="HelloWorld" class="org.xmh.demo.HelloWorld">
<result>/HelloWorld.jsp</result>
</action>
</package>
</struts>
HelloWorld.jsp<%@ page contentType="text/html"; charset="UTF-8" %>
<%@ taglib prefix="s" uri="/struts-tags" %><html>
<head>
<title>Hello World!</title> </head>
<body>
<h2>
<s:property value="message"/>
</h2>
</body>
</html>
Tomcat总是报404错误The requested resource (/HW/HelloWorld.action) is not available.
我现在找不出什么错误,是Tomcat还是代码问题,那位大大帮个忙啊
改为<result name="success" type="redirect">/HelloWorld.jsp</result>
<package name="default" extends="struts-default">
<action name="HelloWorld" class="org.xmh.demo.HelloWorld">
<result>/HelloWorld.jsp</result>
</action>
</package>
</struts>
把包名改成default直接取请求。http://127.0.0.1:8080/工程名/HelloWorld.action
这里name对不对啊
<result>/HelloWorld.jsp</result>
路径肯定不对
<result>HelloWorld.jsp</result>
严重: Error filterStart
2010-7-8 8:26:22 org.apache.catalina.core.StandardContext start
严重: Context [/HW] startup failed due to previous errors
2010-7-8 8:26:24 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
信息: Parsing configuration file [struts-default.xml]
2010-7-8 8:26:25 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
信息: Unable to locate configuration files of the name struts-plugin.xml, skipping
2010-7-8 8:26:25 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
信息: Parsing configuration file [struts-plugin.xml]
2010-7-8 8:26:25 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
信息: Parsing configuration file [struts.xml]
2010-7-8 8:26:26 org.apache.coyote.http11.Http11BaseProtocol start
信息: Starting Coyote HTTP/1.1 on http-8080
2010-7-8 8:26:26 org.apache.jk.common.ChannelSocket init
信息: JK: ajp13 listening on /0.0.0.0:8009
2010-7-8 8:26:26 org.apache.jk.server.JkMain start
信息: Jk running ID=0 time=0/47 config=null
2010-7-8 8:26:26 org.apache.catalina.storeconfig.StoreLoader load
信息: Find registry server-registry.xml at classpath resource
2010-7-8 8:26:27 org.apache.catalina.startup.Catalina start
信息: Server startup in 49235 ms
web项目不能这么干
HelloWorld.jsp放在webroot下后 http://localhost:8080/HelloWorld.action其他的配置没有写错
改成
<package name="tutorial" namespace="/" extends="struts-default">看看行不行。
2010-7-8 8:40:15 org.apache.catalina.core.StandardContext start
严重: Error filterStart
2010-7-8 8:40:15 org.apache.catalina.core.StandardContext start
严重: Context [/HW] startup failed due to previous errors
是http://服务器IP:端口号/HW/HelloWorld.action 吗?
试试这个
别的都别改
commons-io-1.3.2.jar,commons-fileupload-1.2.1.jar这两个包加上去filter error 可以参考:
http://www.blogjava.net/weikj/archive/2009/04/01/108079.html有可能是filter根本就没有作用,导致struts2根本就没配置好。
有人说tomcat5.5以上的版本才支持struts2
看这个帖子:http://www.0x54.org/p4nny/article.asp?id=156
<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">
<display-name>tutorial</display-name>
<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>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
struts.xml放在src目录下<?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.struts2.action" extends="struts-default">
<action name="helloword" class="com.struts2.action.HelloWorldAction">
<result>jsp/success.jsp</result>
</action>
</package>
</struts>
web.xml放在webroot/WEB-INF下<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<!-- action过滤器 -->
<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>charcode</filter-name>
<filter-class>com.strtus2.filter.CharEncodeFilter</filter-class>
<init-param>
<param-name>encode</param-name>
<param-value>utf-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>charcode</filter-name>
<url-pattern>*.action</url-pattern>
</filter-mapping>
-->
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>首页index.jsp放在webroot目录下(日,没有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>Insert title here</title>
</head>
<body>
<a href="helloword.action">Click Me</a>
</body>
</html>
success.jsp放在webroot/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>Insert title here</title>
</head>
<body>
<%out.print("hello world"); %>
</body>
</html>这个应该不用说了吧package com.struts2.action;import com.opensymphony.xwork2.ActionSupport;public class HelloWorldAction extends ActionSupport{ @Override
public String execute() throws Exception {
return SUCCESS;
}
}
--------------------------------------------------------------------------------Apache Tomcat/5.5.26
没有定义一个namespace 为/ 并且action为HelloWorld的Action配置成<package name="tutorial" namespace="/" extends="struts-default">
应该就不会报这个错了。
<package name="tutorial" namespace="/" extends="struts-default">
<action name="HelloWorld" class="org.xmh.demo.HelloWorld">
<result>/HelloWorld.jsp</result>
</action>
</package>
HTTP Status 500 - --------------------------------------------------------------------------------type Exception reportmessage description The server encountered an internal error () that prevented it from fulfilling this request.exception org.apache.jasper.JasperException: /HelloWorld.jsp(1,1) Unterminated <%@ page tag
org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:40)
org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:407)
org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:132)
org.apache.jasper.compiler.Parser.parseDirective(Parser.java:521)
org.apache.jasper.compiler.Parser.parseElements(Parser.java:1557)
org.apache.jasper.compiler.Parser.parse(Parser.java:127)
org.apache.jasper.compiler.ParserController.doParse(ParserController.java:212)
org.apache.jasper.compiler.ParserController.parse(ParserController.java:101)
org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:156)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:296)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:277)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:265)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:564)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:302)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:389)
note The full stack trace of the root cause is available in the Apache Tomcat/5.5.26 logs.
--------------------------------------------------------------------------------Apache Tomcat/5.5.26
tomcat启动时还报如下错误吗?
2010-7-8 8:26:22 org.apache.catalina.core.StandardContext start
严重: Error filterStart
2010-7-8 8:26:22 org.apache.catalina.core.StandardContext start
严重: Context [/HW] startup failed due to previous errors (这行错误表名你项目根本就没发布起来)
2010-7-8 9:29:20 org.apache.catalina.startup.HostConfig checkResources
信息: Reloading context [/HW]
2010-7-8 9:29:21 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
信息: Parsing configuration file [struts-default.xml]
2010-7-8 9:29:22 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
信息: Unable to locate configuration files of the name struts-plugin.xml, skipping
2010-7-8 9:29:22 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
信息: Parsing configuration file [struts-plugin.xml]
2010-7-8 9:29:22 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
信息: Parsing configuration file [struts.xml]
你可以在该jsp上只显示helloworld 看看。其他的逻辑先去掉。
你要实现 的是什么?
通过URL http://localhost:8080/HW/HelloWorld.action
来找到HW工程中的ACTION.吗?
然后让其转到HelloWorld.jsp。是这样吗?struts.xml 中搞了半天,你写的是没什么问题,可是你的jsp页面,开头有问题。
用这个<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
替换你的开头
少写了ACTION的name=success改为 <package name="default" extends="struts-default">
<action name="HelloWorld" class="org.xmh.demo.HelloWorld">
<result name="success">/HelloWorld.jsp</result>
</action>
</package>我已经在我这里成功了。你再试试看。
改成 <%@ page contentType="text/html;charset=UTF-8" %>text/html;charset=UTF-8 应该都在contentType 中
HTTP Status 500 - --------------------------------------------------------------------------------type Exception reportmessage description The server encountered an internal error () that prevented it from fulfilling this request.exception org.apache.jasper.JasperException: /HelloWorld.jsp(1,1) Unterminated <%@ page tag
org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:40)
org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:407)
org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:132)
org.apache.jasper.compiler.Parser.parseDirective(Parser.java:521)
org.apache.jasper.compiler.Parser.parseElements(Parser.java:1557)
org.apache.jasper.compiler.Parser.parse(Parser.java:127)
org.apache.jasper.compiler.ParserController.doParse(ParserController.java:212)
org.apache.jasper.compiler.ParserController.parse(ParserController.java:101)
org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:156)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:296)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:277)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:265)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:564)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:302)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:389)
note The full stack trace of the root cause is available in the Apache Tomcat/5.5.26 logs.
--------------------------------------------------------------------------------Apache Tomcat/5.5.26
跳转名称缺少, name = "success"
import java.text.DateFormat;
import com.opensymphony.xwork2.ActionSupport;public class HelloWorld extends ActionSupport {
private String message;
public String getMessage(){
return message;
}
public String execute(){
message="Hello World,Now is"+ DateFormat.getInstance().format(new Date());
return SUCCESS;
}}
lz 你这里 明明是两个 方法,两个return
我个人 觉得 你<struts>
<package name="tutorial" extends="struts-default">
<action name="HelloWorld" class="org.xmh.demo.HelloWorld">
<result>/HelloWorld.jsp</result>
</action>
</package>
</struts>
的 <result>/HelloWorld.jsp</result>
应改为 <result name="SUCCESS">/HelloWorld.jsp</result>
你看看 行不行?
404错误无非就是.jsp文件找不到,action路径找不到等等
是你的jsp的问题,你仔细看看在第一行第一列,好像是,看看你写错没有了,一般报500错误就是有无法解析的代码!
你确定是按我写的写的吗?
你的jsp文件开头,真的是在myeclipse中自已创建的?
不是copy过来的?