一、jsp默认设置
1、当访问的Action不存在时,页面会显示错误信息,可以通过配置默认Action处理用户异常的操作;
2。配置方法:
在struts.xml文件中的下添加如下内容:
其中index为默认Action的name属性值;
3、配置默认Action后,相应的namespace下不存在要访问的Action时,自动跳转到默认Action处理。
4、实例
web.xml:
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">
hello.jsp
struts2
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
struts2
/*
struts.xml:
/p>
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
/index.jsp
index.jsp:
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
IndexWelcome to Magci's BLOG!
二、action默认设置转发
page_toIndex
/WEB-INF/jsps/index.jsp
/WEB-INF/jsps/admin/admin_login.jsp
action
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。