首页 > 其他 > 详细

struts2第一个程序 Helloworld

时间:2017-07-29 23:55:36      阅读:356      评论:0      收藏:0      [点我收藏+]

1. 新建项目: MyStruts2

2.导入相应的jar包:

技术分享

3.修改web.xml文件:

    <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>

小插曲:刚开始把filter写成了servlet,导致一直报错,后来才发现写错了,所以写的时候要细心

4.在src下新建: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>
    <package name="helloworld" extends="struts-default">
        <action name="product-input">
            <result>/input.jsp</result>
        </action>
    </package>
</struts>

5.新建:index.jsp,主要代码如下:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
    <a href="product-input.action">product-input</a>
</body>
</html>

6.新建:input.jsp,主要代码如下:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
    input.jsp
</body>
</html>

7.将项目部署到tomcat上并启动

8.在浏览器地址栏:http://localhost:8080/MyStrust2/

技术分享

9.点击链接进入后结果如下:

技术分享

10.项目结构如下:

技术分享

 

struts2第一个程序 Helloworld

原文:http://www.cnblogs.com/beibidewomen/p/7257897.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!