Java Web framework-----------------------struts2 (website Tutorial version Helloworld)

Source: Internet
Author: User
Tags html form tomcat server

Java Web framework------------------struts2 (website Tutorial version Helloworld)



We all know that struts is one of the three most common Java Web frameworks, plus spring, Hibernate. Learning Struts is a must.


To! So how to learn it? My advice is to:

1, for the English ability can also people, learn technology we have to learn from the official website document, and then combine the Chinese people wrote papers, blogs, videos


such as This can achieve a multiplier effect.


2, for reading English a little difficult people, we can download Youdao dictionary, and then to this computer professional English book, do not understand on the search, but,


We must not flinch in the face of English. Because the official website technology is the most standard, almost all technical books are based on the official website of the document derivative


Out of it.



Below we based on the official website of the document, the Struts2.3.30 version of the HelloWorld to Write.


First create the DYNAMICN Web project on eclipse, and after that, my directory structure is like This.


650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/87/51/wKiom1fctMSTT9r2AABzZyuHSrY133.png-wh_500x0-wm_3 -wmp_4-s_3618455364.png "title=" qq20160917111218.png "alt=" wkiom1fctmstt9r2aabzzyuhsry133.png-wh_50 "/>



After setting up the directory structure, we will have to do some configuration of the relevant files!


Helloworld.java (which is actually an Action)


The official website about action is described as Follows:

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

That's you Provide. These classes is 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 are 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&nbsp: "; 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;    }}


Xml

<?xml version= "1.0" encoding= "UTF-8"? ><web-app 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 "> <display-name>my Application </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></web-app>


Struts.xml (the file is in the web-inf/classes Directory)

<?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 "> <acti On name= "HelloWorld" class= "tutorial. HelloWorld "> <result>/helloworld.jsp </result> </action> </package ></struts>


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" >


Once written, run on the Tomcat server!

This article is from the "@coder" blog, be sure to keep this source http://smallcoder.blog.51cto.com/11941149/1853308

Java Web framework-----------------------struts2 (website Tutorial version Helloworld)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.