package cn.itcast.action;public class HelloWorldAction {
private String message;


public String execute(){
message = "struts的第一个应用";
return "success";
}
public String getMessage() {
return message;
}
}
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    
    <title>My JSP 'hello.jsp' starting page</title>
    
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">    
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->  </head>
  
  <body>
  ${ message }
  </body>
</html>
<?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="itcast" namespace="/test" extends="struts-default">
<action name="helloworld" class="cn.itcast.action.HelloWorldAction" method="execute">
<result name="success">/WEB-INF/page/hello.jsp</result>
</action>
</package>
 </struts><?xml version="1.0" encoding="UTF-8"?>
<web-app 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">

    <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>http://localhost:8080/Struts2222/test/helloworld  项目是 Struts2222 在地址栏 输入这个 访问不到   为什么 

解决方案 »

  1.   

    你以前用的struts1?它里面可以这样用,但是struts2必须helloworld.action或者你设置 了 struts.action.extension = do后,用 .do 也行,当然别的后缀也行。
      

  2.   

    访问地址修改如下:
    http://localhost:8080/Struts2222/test/helloworld.action
    如果还没有,建议查看下服务器的日志。看是否项目报错。
    而且访问不到是什么意思?
    404错误还是500错误?写明白些。
      

  3.   

    加上 .action 访问试试
    有错把报的异常贴出来
      

  4.   

    同意上边的。action ,要是没出来说下异常
      

  5.   

    楼主,我不熟悉struts2,但我知道你的jsp还没有引入struts2.tld文件啊 
      

  6.   

    你确定你的项目部署的时候也是这个名字吗?使用MyEclipse开发的吧,右键你的项目名,properties--》web--》Web Cotext-root看你的后面是什么?是否是你的那个名字
      

  7.   

    同意上边的。action ,要是没出来说下异常
      

  8.   

    <result name="success">/WEB-INF/page/hello.jsp</result>
    你确定你的文件是存放在这的?
      

  9.   

    先把strtus.xml配置文件中namespace="/test"不要试试
      

  10.   

    找不到什么,是找不到action还是找不到JSP 错误信息贴出来啊
    楼上盆友们说的都有道理,struts2是以xxx.action的形式访问的 再就是JSP路径问题