strutsdemo
2017-01-08 10:06
447 查看
1.开发前的准备
1.下载并部署tomcathttp://jingyan.baidu.com/article/2c8c281daa77aa0008252aff.html
2.为eclipse指定浏览器
3.设置jsp页面编码
4.新建一个dynamic Web Project项目firstWeb,在web-content下新建一个index.jsp页面
5.以上说明步骤完成,说明eclipse部署tomcat成功
6.下载structs2开发包,位struts开发做准备
http://download.csdn.net/detail/hjx2710/3298699
2.创建strutsdemo
**jsp页面报错参考http://jingyan.baidu.com/article/7f766dafbb5cf34101e1d0d8.html
1.创建Dynamic Web project —StrutsDemo
2.导入struts需要的jar包
3.编写工程配置文件
下面是文件的总目录
新建工程配置文件web.xml
<?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/j2ee" xmlns:web="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd http://xmlns.jcp.org/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_9" version="2.4"> <display-name>Struts Blank</display-name> <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>
4.添加struts.properties配置文件,设置常量
struts.i18n.encoding=UTF-8
5.编写struts.xml配置文件
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd"> <struts> <!-- 配置包 包名为default,该包继承了struts2框架的默认包struts-default --> <package name="default" namespace="/" extends="struts-default"> <!-- 定义名为helo的action,该action的处理类为com.action.TestAction的处理类,并映射到success.jsp --> <action name="hello" class="com.action.TestAction"> <result>/success.jsp</result> </action> </package> </struts>
6.开发前端页面index.jsp和success.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib prefix="s" uri="/struts-tags" %> <!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> <s:a action="hello">hello</s:a> </body> </html>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib prefix="s" uri="/struts-tags"%> <!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> <s:property value="helo"/> </body> </html>
7.编写后台处理程序
package com.action; import com.opensymphony.xwork2.ActionSupport; public class TestAction extends ActionSupport{ private static final long serialVersionUID=1L; private String helo; public String getHelo() { return helo; } public void setHelo(String helo) { this.helo = helo; } @Override public String execute() throws Exception { helo="hello,world"; return SUCCESS; } }
8.测试工程
9.结果如下
10.案例下载地址
http://download.csdn.net/detail/myvanguard/9731809
相关文章推荐
- Spring事务隔离级别和事务的传播属性
- 使用Ajax进行文件与其他参数的上传功能(java开发)
- MyEclipse工程项目转到IDEA
- java将流转换成字符串
- Java 多线程:synchronized
- 《JAVA与模式》之观察者模式
- Java程序:自动生成一个n阶矩阵
- 【管我原创不原创,评论啊】自学的Springboot
- Java单元测试框架Junit
- spring容器创建bean时对属性中含有日期的处理方法
- Struts2学习笔记
- JAVA中关于double数据四舍五入的方法
- Java中子类重写父类方法的思想本质!
- 第7天(就业班) Dom4j修改xml、xPath技术、SAX解析
- java根据数据库表内容生产树结构json数据的方法
- Java引用类型与常量
- Java数据类型转换
- java json技术比较
- SpringBoot学习(3) 配置MyBatis
- JavaWeb学习之路(二)--- 数据库操作优化