欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

詳解Struts2中配置默認(rèn)Action的方法

 更新時(shí)間:2018年01月15日 09:10:35   作者:SIHAIloveYAN  
本篇文章主要介紹了詳解Struts2中配置默認(rèn)Action的方法,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧

一、jsp默認(rèn)設(shè)置

1、當(dāng)訪問的Action不存在時(shí),頁面會(huì)顯示錯(cuò)誤信息,可以通過配置默認(rèn)Action處理用戶異常的操作;

2。配置方法:

在struts.xml文件中的下添加如下內(nèi)容:

<default-action-ref name="index"></default-action-ref>

其中index為默認(rèn)Action的name屬性值;

3、配置默認(rèn)Action后,相應(yīng)的namespace下不存在要訪問的Action時(shí),自動(dòng)跳轉(zhuǎn)到默認(rèn)Action處理。

4、實(shí)例

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

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.enable.DynamicMethodInvocation" value="false" />
 <constant name="struts.devMode" value="false" />
 <include file="example.xml"/>

 <package name="default" namespace="/" extends="struts-default">
  <default-action-ref name="index" />
  <action name="index">
   <result type="redirectAction">
    <param name="actionName">HelloWorld</param>
    <param name="namespace">/example</param>
   </result>
  </action>
 </package>
  -->

 <!-- Add packages here -->
 <constant name="struts.devMode" value="true" />
 <constant name="struts.i18n.encoding" value="GBK"></constant>
  <package name="user" namespace="/" extends="struts-default">
   <default-action-ref name="index"></default-action-ref>
  <action name="index">
   <result>/index.jsp</result>
  </action>
 </package>
</struts>

index.jsp:

<%@ page language="java" import="java.util.*" pageEncoding="GB18030"%>
<%
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%>" rel="external nofollow" >
 <title>Index</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" rel="external nofollow" >
 -->
 </head>

 <body>
 Welcome to Magci's BLOG!<br />
 <a href="magci/magc" rel="external nofollow" >magci/magc</a><br />
 <a href="mgc/magc/magci/123456" rel="external nofollow" >mgc/magc/magci/123456</a><br />
 </body>
</html>

二、action默認(rèn)設(shè)置轉(zhuǎn)發(fā)

<!-- 默認(rèn)action -->
  <default-action-ref name="index" />
  <action name="index">
   <result type="redirectAction">
    <param name="actionName">page_toIndex</param>
    <!-- <param name="namespace">/example</param> -->
   </result>
  </action>

  <action name="page_*" class="indexAction" method="{1}">
   <result name="toIndex">/WEB-INF/jsps/index.jsp</result>
   <result name="toAdminLogin">/WEB-INF/jsps/admin/admin_login.jsp</result>

   <!-- ajax -->
   <result name="ajaxInsertOneCallback" type="json">
    <param name="root">action</param>
   </result>
  </action>

以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • SpringBoot異常處理器的使用與添加員工功能實(shí)現(xiàn)流程介紹

    SpringBoot異常處理器的使用與添加員工功能實(shí)現(xiàn)流程介紹

    設(shè)計(jì)完了登錄與退出功能還只完成了冰山一角,經(jīng)過測試發(fā)現(xiàn),我們以u(píng)rl的方式來訪問網(wǎng)站時(shí)可以直接跳過登陸頁面進(jìn)入后臺(tái)頁面,這樣顯然是不合理的,下面我們通過異常攔截器+boot來做到訪問限制,以及實(shí)現(xiàn)新增員工功能,制作全局異常處理器
    2022-10-10
  • 詳解Java中的迭代迭代器Iterator與枚舉器Enumeration

    詳解Java中的迭代迭代器Iterator與枚舉器Enumeration

    Iterator與Enumeration分別是實(shí)現(xiàn)迭代器和枚舉器類的接口,下面就帶大家來詳解Java中的迭代迭代器Iterator與枚舉器Enumeration,以及它們之間的區(qū)別.
    2016-05-05
  • 解決創(chuàng)建springboot后啟動(dòng)報(bào)錯(cuò):Failed?to?bind?properties?under‘spring.datasource‘

    解決創(chuàng)建springboot后啟動(dòng)報(bào)錯(cuò):Failed?to?bind?properties?under‘spri

    在Spring?Boot項(xiàng)目中,application.properties和application.yml是用于配置參數(shù)的兩種文件格式,properties格式簡潔但不支持層次結(jié)構(gòu),而yml格式支持層次性,可讀性更好,在yml文件中,要注意細(xì)節(jié),比如冒號(hào)后面需要空格
    2024-10-10
  • java打包maven啟動(dòng)報(bào)錯(cuò)jar中沒有主清單屬性

    java打包maven啟動(dòng)報(bào)錯(cuò)jar中沒有主清單屬性

    本文主要介紹了java打包maven啟動(dòng)報(bào)錯(cuò)jar中沒有主清單屬性,可能原因是創(chuàng)建springboot項(xiàng)目時(shí),自動(dòng)導(dǎo)入,下面就來介紹一下解決方法,感興趣的可以了解一下
    2024-03-03
  • 詳解MyBatis中column屬性的總結(jié)

    詳解MyBatis中column屬性的總結(jié)

    在MyBatis的映射中有column這么一個(gè)屬性,我一直以為它映射的是數(shù)據(jù)庫表中的列名,但經(jīng)過學(xué)習(xí)發(fā)現(xiàn)他似乎映射的是SQL語句中的列名,或者說是查詢結(jié)果所得到的表的列名,這篇文章主要介紹了MyBatis中column屬性的總結(jié),需要的朋友可以參考下
    2022-09-09
  • MyBatis實(shí)現(xiàn)MySQL批量插入的示例代碼

    MyBatis實(shí)現(xiàn)MySQL批量插入的示例代碼

    本文主要介紹了MyBatis實(shí)現(xiàn)MySQL批量插入的示例代碼,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2023-05-05
  • IDEA 包轉(zhuǎn)模塊的解決步驟

    IDEA 包轉(zhuǎn)模塊的解決步驟

    很多朋友遇到這樣一個(gè)問題,直接在idea拉取代碼,發(fā)現(xiàn)創(chuàng)建的模塊包類型不一樣了,類似這樣的問題該如何處理呢?很多朋友向小編求助,在這統(tǒng)一回答大家,需要的朋友參考下本文吧
    2021-06-06
  • Redis 集成Spring的示例代碼(spring-data-redis)

    Redis 集成Spring的示例代碼(spring-data-redis)

    本篇文章主要介紹了Redis 集成Spring的示例代碼(spring-data-redis) ,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-09-09
  • MyBatis中map的應(yīng)用與模糊查詢實(shí)現(xiàn)代碼

    MyBatis中map的應(yīng)用與模糊查詢實(shí)現(xiàn)代碼

    這篇文章主要介紹了MyBatis中map的應(yīng)用與模糊查詢實(shí)現(xiàn)代碼,文中通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2021-11-11
  • 基于java的opencv開發(fā)過程詳解

    基于java的opencv開發(fā)過程詳解

    這篇文章主要介紹了基于java的opencv開發(fā)過程詳解,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2021-04-04

最新評(píng)論