首页 > 代码库 > struts-修改主题、扩展名、自动加载
struts-修改主题、扩展名、自动加载
创建项目
struts2101403
添加jar包
commons-fileupload-1.3.jar
commons-io-2.0.1.jar
commons-lang3-3.1.jar
freemarker-2.3.19.jar
javassist-3.11.0.GA.jar
ognl-3.0.6.jar
struts2-core-2.3.15.1.jar
xwork-core-2.3.15.1.jar
src
创建包
cn.jbit.strut2101403.web.action
创建实体类
@Override
public String execute() throws Exception {
return super.execute();
}
conf
添加struts.xml配置文件
<?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>
<!-- 修改主题 -->
<constant name="struts.ui.theme" value="http://www.mamicode.com/simple"></constant>
<!-- 修改struts请求的扩展名 -->
<constant name="struts.action.extension" value="http://www.mamicode.com/do"></constant>
<!-- 自动加载struts.xml文件 -->
<!-- <constant name="struts.configuration.xml.reload" value="http://www.mamicode.com/true"></constant> -->
<!-- 配置开发模式 -->
<constant name="struts.devMode" value="http://www.mamicode.com/true"></constant>
<package name="default" namespace="/" extends="struts-default">
<default-action-ref name="defaultAction"></default-action-ref>
<!--
没有Class会执行ActionSupport
-->
<action name="noClassAction">
<result name="success">/WEB-INF/pages/success.jsp</result>
</action>
<!--
默认Action
-->
<action name="defaultAction" class="cn.jbit.strut2101403.web.action.DefaultAction">
<result>/WEB-INF/pages/default.jsp</result>
</action>
<action name="noClassAction1">
<result name="success">/WEB-INF/pages/success.jsp</result>
</action>
</package>
</struts>
web.xml
<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>
test
创建登录页面index.jsp
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%
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="http://www.mamicode.com/">
<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="http://www.mamicode.com/styles.css">
-->
</head>
<body>
<a href="http://www.mamicode.com/${pageContext.request.contextPath}/noClassAction.do">noClassAction</a><br/>
<a href="http://www.mamicode.com/${pageContext.request.contextPath}/noClassAction1.do">noClassAction</a><br/>
<a href="http://www.mamicode.com/${pageContext.request.contextPath}/noAction.action">请求一个没有配置的Action</a><br/>
</body>
</html>
在WebRoot/WEB-INF/pages创建登录,注册,错误页面
error.jsp
登录失败
default.jsp
默认页面
success.jsp
noClassAction
本文出自 “素颜” 博客,请务必保留此出处http://suyanzhu.blog.51cto.com/8050189/1564324
struts-修改主题、扩展名、自动加载