SSH配置(一)-struts2(convention插件零配置)
来源:互联网 发布:淘宝50字通用好评 编辑:程序博客网 时间:2024/05/17 16:13
一、新建工程
①操作:eclipse下File->New->Dynamic Web Project
②项目目录如下
二、Struts2配置如下
1、拷贝struts2所需的jar包到WebConten->WEB-INF->lib下
2、在src下添加action类文件和在WEB-INF下添加web页面
①在src下添加action类文件
UserAction.java类代码:
package com.jjh.ssh.web;import org.apache.struts2.convention.annotation.Namespace;import org.apache.struts2.convention.annotation.Result;import com.opensymphony.xwork2.ActionSupport;@Namespace("/user")@Result(name = "userlist", location = "userlist.jsp")public class UserAction extends ActionSupport {/** * 获取用户列表 * @return * @throws Exception */public String listUsers() throws Exception{System.out.println("-------listusers action begin-------");System.out.println("-------listusers action end-------");return "userlist";}}②在WEB-INF下添加view->user->userlist.jsp
userlist.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>userlist for this.</body></html>
3、在src目录下添加struts.xml 和 struts.properties
①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></struts>
②struts.properties
#strutsstruts.action.extension=dostruts.ognl.allowStaticMethodAccess=true#struts-devstruts.devMode=truestruts.i18n.reload=true#struts-conventionstruts.convention.action.packages=com.jjhstruts.convention.package.locators=web struts.convention.result.path=/WEB-INF/view#struts-convention-devstruts.convention.classes.reload=true
4、配置web.xml
添加struts2的Filter过滤器
<?xml version="1.0" encoding="UTF-8"?><web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"id="WebApp_ID" version="3.0"><display-name>SSHFW</display-name><!-- struts2过滤器 --><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><welcome-file-list><welcome-file>index.jsp</welcome-file></welcome-file-list></web-app>
三、部署到tomcat,运行。
在浏览器中输入http://localhost:8080/SSHFW/user/user!listUsers.do
请求结果显示如下:
- SSH配置(一)-struts2(convention插件零配置)
- STRUTS2 Convention零配置
- struts2 利用struts2-convention-plugin插件实现零配置
- 简述STRUTS2 Convention零配置
- 简述Struts2 Convention零配置
- 简述Struts2 Convention零配置
- 简述Struts2 Convention零配置
- 简述STRUTS2 Convention零配置
- 简述STRUTS2 Convention零配置
- (转)Struts2 Convention零配置
- 简述Struts2 Convention零配置
- 简述STRUTS2 Convention零配置
- 简述Struts2 Convention零配置
- Convention插件实现Struts2.1以上版本零配置
- 使用struts-convention插件来实现struts2零配置
- Struts2 注解零配置方法(convention插件使用)
- Struts2 注解零配置方法(convention插件使用)
- Struts2的零配置插件convention的简单总结
- ArcGIS Server REST API(收藏教程)
- 单片机之旅——拓展的IO接口8255A
- Turn off the rightmost set bit
- Multiply a given Integer with 3.5
- Windows环境下WAMP + MantisBT的架设
- SSH配置(一)-struts2(convention插件零配置)
- Add 1 to a given number
- 黑马程序员_IO(下)
- QQ大文件为何上传这么快
- JVM垃圾收集算法
- SCI简介 引文数据分析和同行评估
- Mac下更新SVN
- 查詢SQL Server 鎖表的SQL
- linux下openoffice的安装配置