Struts2 2.3.30版本的HelloWorld简单例子
2016-08-28 00:00
232 查看
这个是struts.xml配置:只是简单的配置了<action>的name属性,以及<result>指向页面(/WEB-INF/pages/input.jsp)
下面的这个是web.xml配置信息 ,只需要将Struts2下载的文件中的web.xml中的部分扣下来即可!
下面的是/WEB-INF/pages下的input.jsp页面
再导入相应的jar包
就可以实现Struts2的简单例子了(如图)
<?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="helloWord" extends="struts-default"> <action name="product-input"> <result>/WEB-INF/pages/input.jsp</result> </action> </package> </struts>
下面的这个是web.xml配置信息 ,只需要将Struts2下载的文件中的web.xml中的部分扣下来即可!
<?xml version="1.0" encoding="UTF-8"?> <web-app id="starter" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> <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>
下面的是/WEB-INF/pages下的input.jsp页面
<%@ page language="java" import="java.util.*" 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"> <html> <head> <base href="<%=basePath%>"> <title>My JSP 'input.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"> <!-- <link rel="stylesheet" type="text/css" href="styles.css"> --> </head> <body> <!--输入文本框以及提交按钮--> <form action="product-save.action" method="post"> ProductName:<input type="text" name="productName"/><br/> ProductDesc:<input type="text" name="productDesc"/><br/> ProductPrice:<input type="text" name="productPrice"/><br/> <input type="submit" value="submit"/> </form> </body> </html>
再导入相应的jar包
就可以实现Struts2的简单例子了(如图)
相关文章推荐
- struts2的搭建和简单的例子(采用struts-2.5.2版本)
- 从Red5的win版本安装到简单的hello world例子
- 在Struts2的官方网站上,有doubleselect的用法示例,但是那个例子比较简单。 <s:doubleselect label="doubleselect test2" name="menu" list="#{'fruit':'Nice Fruit
- struts2中Jquery的json使用(最简单的例子)
- Struts2基础学习(1)-简单例子与基本配置
- jquery autocomplete 与struts2 json插件结合简单例子
- Struts 教程I:一个用jbuilder X 做的最简单的helloworld的struts例子
- struts2 标签登陆例子(简单)
- struts2 +jquery+ajax简单小例子
- Java Web : Struts2第一个简单例子 浅解
- Struts2中使用验证框架的简单例子
- struts2最简单的例子
- Struts2的简单例子
- libvlc简单例子(1.1.0以后版本)vs2008
- 第一节:最简单的例子 向控制台输出HelloWorld
- Ruby on rails3新手谈(2):简单的例子helloworld
- Struts2 + Spring 整合简单例子(转)
- Struts2 简单的文件上传例子,一看就懂。
- struts2 一个简单的 struts2程序(HelloWorld)