struts學習日記1
阿新 • • 發佈:2018-11-10
一.配置一個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>