Struts2基础-helloworld
来源:互联网 发布:社交软件 系统架构 编辑:程序博客网 时间:2024/06/10 18:59
Struts2开发步骤
1.新建web工程Strutsdemo并引入jar包:
commons-fileupload-1.2.1.jar
freemarker-2.3.15.jar
ognl-2.7.3.jar
struts2-core-2.1.8.jar
xwork-core-2.1.6.jar
2.在web.xml中添加控制器配置:
<?xml version="1.0" encoding="UTF-8"?><web-app 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>strutsdemo</filter-name><filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class></filter><filter-mapping><filter-name>strutsdemo</filter-name><url-pattern>/*</url-pattern></filter-mapping></web-app>3.创建action
package demo; public class Test { private String name;public String execute(){name = "hello world";return "success";}public String getName() {return name;}}
4.在src下创建struts.xml配置文件:
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1.7//EN" "http://struts.apache.org/dtds/struts-2.1.7.dtd"><struts><package name = "demo1" extends = "struts-default"><action name = "welcome" class = "demo.Test"><result name = "success">hello.jsp</result></action></package></struts>
5.创建hello.jsp文件
<html> <head> <title>demo</title> </head> <body> ${name } <br> </body></html>
6.在浏览器地址栏发送请求:
http://127.0.0.1:8888/Strutsdemo/welcome.action
浏览器显示:
hello world
- Struts2基础-helloworld
- Struts2基础之一:Struts2的配置和HelloWorld
- Struts2 ------ HelloWorld
- Struts2 helloWorld
- struts2 HelloWorld
- struts2 HelloWorld
- struts2 helloworld
- Struts2,HelloWorld
- struts2 helloworld
- Struts2 HelloWorld
- Struts2 HelloWorld!
- struts2-helloworld
- struts2-helloworld
- Struts2(一)-Struts2之HelloWorld
- Struts2的HelloWorld程序
- Struts2.0.1HelloWorld
- 转:Struts2.0.1HelloWorld
- Struts2之HelloWorld程序
- C#:代表(delegate)和事件(event)
- Android中如何在QQ通讯录,360之前拦截短信
- OpenGL ES2.0编程三步曲
- SPI、IIC、UART区别
- ubuntu安装git出错分析
- Struts2基础-helloworld
- javascript中的apply和call
- 【模式识别与机器学习】模式识别中的一些基本概念
- 程序员说。。。。
- 分布式和集群
- C实现 BinaryCode
- 常见中文分词比较
- How to encrypt weblogic password.
- JavaScript学习总结