struts学习日记1

一.配置一个struts 界面
1.导入struts依赖包
在这里插入图片描述
2.配置struts中央处理器

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd" id="WebApp_ID" version="4.0">
  <display-name>struts</display-name>
 	<filter>
 		<filter-name>struts</filter-name>
 		<filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class><!--StrutsPrepareAndExectteFilter类的全限类名 -->
 	</filter>
 	<filter-mapping>
 		<filter-name>struts</filter-name>
 		<url-pattern>/*</url-pattern>
 	</filter-mapping>
</web-app>

3.添加struts支持
在这里插入图片描述
4.创建一个HolleAction的类

package com.Dome1;

public class HolloAction {
	public String execute() {//默认调用execute方法
		System.out.println("Hollo struts");
		return "success"; //返回结果码
	}
}

5.创建sussess.jsp界面

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
HolleStruts
</body>
</html>

6.在struts-sy.xml配置

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
	"-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"
	"http://struts.apache.org/dtds/struts-2.5.dtd">
<struts>
	<package name="sy" extends="base" namespace="/sy">
		<action name="helloAction" class="com.Dome1.HolloAction">
			<result name="success">/success.jsp</result>
		</action>

	</package>
</struts>

猜你喜欢

转载自blog.csdn.net/qq_41282789/article/details/83021936