struts2 第一个程序 以及错误There is no Action mapped for action name hello 解决


Struts2使用步骤

1创建一个javaweb project

2添加struts2基本类库

3在web.xml中添加前端控制器

4在src文件夹下建立配置文件 struts.xml

5编写控制器action

6编写视图jsp

步骤1


步骤2



拷贝jar包后 add building path 

步骤3 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">
	<display-name></display-name>
	<filter>
		<filter-name>struts</filter-name>
		<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
	</filter>
	<filter-mapping>
		<filter-name>struts</filter-name>
		<url-pattern>/*</url-pattern>
	</filter-mapping>
	<welcome-file-list>
		<welcome-file>index.jsp</welcome-file>
	</welcome-file-list>
	
</web-app>

步骤4 struts.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
    "http://struts.apache.org/dtds/struts-2.3.dtd">
    
    <struts>
    
    <package name="one" namespace="day01" extends="struts-default">
    	<action name="hello" class="com.liangjing.action.HelloAction">
    	<result> /index.jsp </result> 
    	</action>
    </package>
    </struts>

步骤5 HelloAction.java

package com.liangjing.action;

public class HelloAction {

	public HelloAction(){
		
		System.out.println("HelloAction()...");
	}
	
	public String execute(){
		
		System.out.println("HelloAction.execute()...");
		return "success";
	}
}

步骤6  index.jsp

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'index.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>
    This is my JSP page. <br>
  </body>
</html>

经过如上步骤 出现如下错误 




将步骤4中

namespace="day01"

 改成 

namespace="/day01"

输出结果


myeclipse输出


第一个struts2 程序结束



=======================================================================================

struts2执行流程 

1请求提交给前端控制器

2根据配置信息确定要调用的action

3创建一个ValueStack

4创建Action,把Action放到ValueStack栈顶

5调用Action的方法,根据输入属性算输出属性

6在调用Action前后 ,调用拦截器Interceptor

7根据Action返回的字符串,确定result

8调用result将ValueStack中的数据按照特定的格式输出

9很多情况下result转到jsp


struts的核心组件

1前端控制器

2值栈ValueStack

3Action

4result

5拦截器Interceptor

6标签Tags



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值