VereWebMVC案例(从数据到前端页面)
打开 Eclipse 新建一个 test 项目 Eclipse -> File -> New -> Dynamic Web Project 将解压后 VereMVC/lib 目录下面的 jar 包拷贝到 test/WebContent/WEB-INF/lib 里面 commons-fileupload-1.2.1.jar commons-io-1.3.2.jar dom4j-1.6.1.jar jaxen-1.1-beta-6.jar VereMVC.jar 将解压后 VereMVC 目录下面的 资源配置 xml 文件 拷贝到 test/src 里面 VereMVC.xml 在 test/WebContent/WEB-INF/web.xml 里面添加支持 VereMVC 配置 <filter> <filter-name>VereMVC</filter-name> <filter-class>com.vere.mvc.dispatcher.filter.VereMVCPrepareFilter</filter-class> </filter> <filter-mapping> <filter-name>VereMVC</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <listener> <listener-class>com.vere.mvc.listener.VereMVCContextListener</listener-class> </listener> 新建一个TestAction 类 test/src -> com.test.action.TestAction package com.test.action; import javax.servlet.http.HttpServletRequest; import com.vere.mvc.ServletActionContext; public class TestAction { public String execute() { HttpServletRequest request = ServletActionContext.getRequest(); request.setAttribute("name", "你好"); return "success"; } } 在 test/src/VereMVC.xml 配置文件中配置 com.test.action.TestAction <action name="account" class="com.test.action.AccountAction"> <result name="success">/test.jsp</result> </action> 在 test/WebContent 中新建一个 test.jsp 文件 <%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Insert title here</title> </head> <body> <% String name=""; if(request.getAttribute("name")!=null) { name=request.getAttribute("name").toString(); } out.write(name); %> </body> </html> 启动 tomcat 在浏览器地址栏输入 http://localhost:8080/test/test 将会看到结果
- 1
- 粉丝: 80
- 资源: 22
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助