struts.xml的配置

 <?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd"> <struts>
<constant name="struts.configuration.xml.reload" value="true"/>
<!--
<constant name="struts.enable.DynamicMethodInvocation" value="false" />
<constant name="struts.devMode" value="true" /> <package name="default" namespace="/" extends="struts-default"> <default-action-ref name="index" /> <global-results>
<result name="error">/error.jsp</result>
</global-results> <global-exception-mappings>
<exception-mapping exception="java.lang.Exception" result="error"/>
</global-exception-mappings> <action name="index">
<result type="redirectAction">
<param name="actionName">HelloWorld</param>
<param name="namespace">/example</param>
</result>
</action>
</package>
<include file="example.xml"/>
--> <!-- Add packages here --> <package name="default" namespace="/" extends="struts-default">
<action name="hello">
<result>/Hello.jsp</result>
</action>
</package> </struts>

namespace 为 "/",action 的 name 为 hello,访问路径就是:http://localhost:8080/Struts2_0100_Introduction/hello.action (.action 可以不要)

Hello.jsp

 <%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<base href="<%=basePath%>" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Hello Struts2</title>
</head>
<body>
<h1>Hello Struts2</h1>
</body>
</html>

部署后即可访问。

代码链接:http://pan.baidu.com/s/1miAy27I 提取码:fhhk

Struts2_HelloWorld_3的更多相关文章

随机推荐

  1. 命令行编译运行Java程序

  2. FileWriter 中午乱码

      解决办法 BufferedWriter writer = new BufferedWriter (new OutputStreamWriter (new FileOutputStream (fil ...

  3. linux系统延时和定时任务

    系统延时任务延时任务:只做一次的at命令: 系统定时及延时任务 延时任务:**有输出任务**不会输出到终端上而是发送邮件给你/var/mail/root/执行 mail at          时间 ...

  4. slf4j与log4j、log4j2

    https://blog.csdn.net/yangzl2008/article/details/81503579 https://blog.csdn.net/HarderXin/article/de ...

  5. java——ArrayList 的存在有什么意义?

    好像所有的数据类型都可以用比如 TreeMap[]  int[] Object[] 这种形式来创建自己的数组,那么ArrayList存在的意义是什么呢? 我只能想到这种:ArrayList可以存储多种 ...

  6. spark项目打jar包,不包含依赖包问题的解决方案

    mvn clean package打包maven-archetype-webapp项目时,打包后的jar包含项目中引用的jar包(解压后,在WEB-INF有一个lib目录,该目录下有所有依赖包). m ...

  7. android Window(一)从setConetView说起

    Activity的源码 首先从setContentView这里调用的mWindow的 setConetView() private Window mWindow; public void setCon ...

  8. list 增 删 改 查 及 公共方法

    # 热身题目:增加名字,并且按q(不论大小写)退出程序 li = ['taibai','alex','wusir','egon','女神'] while 1: username = input('&g ...

  9. How to Fold a Julia Fractal

    How to Fold a Julia FractalA tale of numbers that like to turn http://acko.net/blog/how-to-fold-a-ju ...

  10. 《我在谷歌大脑见习机器学习的一年:Node.js创始人的尝试笔记》阅读笔记

    文章来源:https://www.toutiao.com/i6539751003690893828/?tt_from=weixin_moments&utm_campaign=client_sh ...