配置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.i18n.encoding" value="GBK"></constant> <package name="default" namespace="/" extends="struts-default"> <default-action-ref name="dft"></default-action-ref> <!-- 默认执行的action,比如,客户端访问服务器不存在的action,将自动执行默认action,注意仅限action,JSP页面不行 可以设置对应的class <default-class-ref class=""></default-class-ref> --> <action name="dft"> <result>/default.jsp</result> </action> </package> </struts>
创建default.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%>"> <title>My JSP 'default.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"> </head> <body> 默认页 </body> </html>
执行结果如下图:
浙公网安备 33010602011771号