java struts2官网_Java Web框架-----------------------struts2(官网教程版HelloWorld)

Java Web框架------------------struts2(官网教程版HelloWorld)

我们都知道Struts是Java Web 常用的三大框架之一,另外还有Spring、Hibernate。学习Struts很有必

要!那么怎么学习呢?我的建议是:

1、对于英语能力还可以的人,学技术我们要从官网文档学起,再结合中文别人所写的论文、博客,视频

等。这样可以达到事半功倍的效果。

2、对于阅读英语稍微吃力的人,我们可以下载有道词典,再来本计算机专业英语书,不懂就查,但是,

我们决不能面对英文就退缩。因为官网的技术是最标准的,几乎所有的技术书都是根据官网的文档衍生

出来的。

下面我们就根据官网的文档,就Struts2.3.30版进行HelloWorld的编写。

首先在Eclipse上创建Dynamicn Web project,建立好之后,我的目录结构是这样的。

8876d8fa8b91f1d608a1057800e9f2da.png

建立好目录结构之后,我们就要进行一些相关文件的配置了!

HelloWorld.java(其实就是一个action)

官网关于action是这样描述的:

When you submit a HTML form to the framework, the input is not sent to another server page, but to a Java class

that you provide. These classes are called Actions. After the Action fires, a Result selects a resource to render the

response. The resource is generally a server page, but it can also be a PDF file, an Excel spreadsheet, or a Java

applet window.package tutorial;

import com.opensymphony.xwork2.ActionSupport;

public class HelloWorld extends ActionSupport {

private static final long serialVersionUID = 1L;

public static final String MESSAGE = "Struts is up and running ...";

private String message;

public String execute() throws Exception {

setMessage(MESSAGE);

return SUCCESS;

}

public void setMessage(String message){

this.message = message;

}

public String getMessage() {

return message;

}

}

web.xml<?xml  version="1.0" encoding="UTF-8"?>

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xmlns="http://xmlns.jcp.org/xml/ns/javaee"

xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">

My Application

struts2

org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter

struts2

/*

struts.xml(该文件在上图的WEB-INF/classes目录下)<?xml  version="1.0" encoding="UTF-8" ?>

struts PUBLIC

"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"

"http://struts.apache.org/dtds/struts-2.3.dtd">

/HelloWorld.jsp

HelloWorld.jsp

pageEncoding="UTF-8"%>

html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

Insert title here

编写好之后,在Tomcat服务器上运行即可!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值