Struts2框架的配置(持续更新)

1、constant子元素
constent子元素不包括其他子元素,只有name和value属性。
示例:(主要文件的代码)

inputMessage.jsp:

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

<html>
<head>
    <base href="<%=basePath%>">
    <title>title>
    <meta charset="UTF-8">
    <meta name="keywords" content="keyword1,keyword2,keyword3">
    <meta name="description" content="this is my page">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="content-type" content="text/html; charset=UTF-8">
head>
<body>
<form Action="helloWord.struts2" method="post">
    Message:<input type="text" name="msg"><br/>
    <input type="submit" Value="Submit"/>
form>
body>
html>

inputMessage.jsp
struts.xml:



<struts>
    <package name="default" namespace="/" extends="struts-default">
    <action name="helloWord" class="Helloword">
        <result name="success">/3-12showMessage.jspresult>
        <result name="failed">/3-12noMessage.jspresult>
    action>
    package>
    <constant name="struts.action.extension" value="struts2"/>
struts>

HelloWord.java:

public class Helloword {
    private String msg;

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }
    public String execute() {
        if(getMsg().isEmpty()){
            return "failed";
        }else {
            return "success";
        }
    }
}

这里写图片描述

<constant name="struts.action.extension" value="struts2"/>
很容易理解,借助constant 字句,在struts.xml文件中配置struts.action.extension常量,使Struts框架能够处理请求后缀是struts2的。

你可能感兴趣的:(Struts2,Struts2,web后台,框架技术)