Struts2 入门 hellow word
来源:互联网 发布:怎样手机域名保护 编辑:程序博客网 时间:2024/06/07 00:00
1.添加相应的jar
commons-fileupload-x.y.z.jar
commons-io-x.y.z.jar
commons-lang-x.y.jar
commons-logging-x.y.z.jar
commons-logging-api-x.y.jar
freemarker-x.y.z.jar
javassist-.xy.z.GA
ognl-x.y.z.jar
struts2-core-x.y.z.jar
xwork-core.x.y.z.jar
<?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>struts2</display-name><filter><filter-name>struts</filter-name> //过滤器名称<filter-class> org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class></filter><filter-mapping><filter-name>struts</filter-name><url-pattern>/*</url-pattern></filter-mapping><welcome-file-list><welcome-file>result.jsp</welcome-file></welcome-file-list></web-app>
3.java项目下的.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><package name="default" namespace="/" extends="struts-default"> //都为默认的 namespac="/" 这边为显示的为最后面/ 例如http://localhost:8080/struts2/ <action name="hellowrod" class="com.action.helloword"> //这边的name 为访问时的名称 <result>/result.jsp</result>// 返回的JSP页面为 <result name="add">/add.jsp</result> </action></package></struts>
4.类文件编写package com.action;import com.opensymphony.xwork2.ActionSupport;public class hellowrod extends ActionSupport{ //继承ActionSupprot类@Overridepublic String execute() throws Exception {System.out.println("hello wrod"); //测试打印return SUCCESS; //这边默认反悔SUCCESS 也可以直接放回.XML文件里面定义的name名字}public String add(){return "add";}public String updata(){return "updata";}}
5.jsp页面的编写 result.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> this is result;</body></html>
测试通过hellowrod.action 访问
也可以不用action都可以访问的到
阅读全文
0 0
- Struts2 入门 hellow word
- hellow word
- hellow word
- Struts2入门-Hello Word实例
- Struts2入门+Hello Word实例
- Struts2入门-Hello Word实例
- Struts2入门-Hello Word实例
- hellow
- hellow
- Hellow
- hellow
- ElectroServer 5 安装与Hellow Word!
- 微信小程序开发必备 hellow word
- hellow world!
- Hellow Blog
- Hellow world!!
- Hellow, world!
- Hellow Acmer!
- 测试...
- php正则表达式使用的详细介绍
- 矩阵螺旋输出
- Subsequence (二分)【POJ】-3061
- Webix入门()
- Struts2 入门 hellow word
- java面向对象的三个特征以及匿名内部类
- 注意:父类构造函数与子类构造函数的调用
- Unity Kinect体感开发注意点
- 329. Longest Increasing Path in a Matrix
- std里find和find_if
- Android中的setOffscreenPageLimit()
- 十道海量数据处理面试题与十个方法大总结
- Graphic使UI渐变