Struts2入门(一)
来源:互联网 发布:好用的粉底液推荐知乎 编辑:程序博客网 时间:2024/06/14 19:01
1:helloworld.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>Hello World</title>
</head>
<body>
<h4>Hello World From Struts2</h4>
<form action="hello" method="post">
<label for="name">Please enter your name</label><br/>
<input type="text" name="name"/>
<input type="submit" value="你好"/>
</form>
</body>
</html>
2: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/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_2_5.xsd"
id="WebApp_ID" version="2.5">
<!-- 配置 Struts2 的 Filter -->
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
<init-param>
<param-name>struts.i18n.encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>hello.jsp</welcome-file>
</welcome-file-list>
</web-app>
3:struts.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"
"http://struts.apache.org/dtds/struts-2.5.dtd">
<struts>
<!-- 配置 Struts 可以受理的请求的扩展名 -->
<constant name="struts.i18n.encoding" value="UTF-8"/>
<constant name="struts.action.extension" value="action,do,"></constant>
<package name="hellodemo" extends="struts-default" namespace="/">
<action name="hello" class="cn.itcast.action.HelloAction" method="execute">
<result name="success">/hello.jsp</result>
</action>
</package>
</struts>
4:HelloAction
package cn.itcast.action;
/*
* 访问action,每次访问action时候,默认执行名称为execute方法
*/
public class HelloAction {
private String name;
public String execute() throws Exception {
return "success";
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
5:hello.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>
Hello World<s:property value="name"/>
</body>
</html>
- 【Struts2一】入门
- Struts2入门(一)
- struts2入门(一)
- Struts2入门(一)
- Struts2入门(一)
- Struts2入门学习(一)
- Struts2入门(一)
- Struts2学习笔记一之Struts2入门
- struts2+spring+mybatis入门一
- Struts2自学入门(一)
- 【struts2】(一)入门伊始
- Struts2 入门讲解(一)
- struts2入门程序(一)
- 总结一:Struts2入门与配置
- 传智Struts2笔记(一)入门
- 传智Struts2笔记(一)入门
- java web(二) struts2入门一
- struts2.2.x入门应用(一)
- CSDN安全设置需改进
- CSS基础知识
- 【问题汇总】python操作hbase脚本
- 启动 eclipse 报错:Failed to load the JNI shared jvm.dll
- Professional JS(六-Understanding the object&&factory/constructor/prototype pattern)&enumerable
- Struts2入门(一)
- 如何查看C++内存布局(VS2012)
- What is the difference between the Linux Kernel and the Android Kernel?
- java获取文件夹及子文件夹所有文件名和文件夹名
- 机器学习相关知识
- linux应用编程--信号通讯(上)
- 圣诞树
- 前后端分离后的前端时代
- 我们所说的前端框架与库的区别?