Struts development steps and struts development steps

Source: Internet
Author: User

Struts development steps and struts development steps

To put it bluntly, this simple struts has been tossing around for a long time, and it took about three days to solve it. Below I will summarize the development steps: (I am using MyEclipse );

1. Create an Exercise3 web Project

2. Configure the web. xml file
Add the following code:

<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>
3. Add a class library

Place the jar package for example under WEB-INF/lib



4. Create a class

The Code is as follows:

Package cn. wwh. www. struts;/*** function: ** @ author @ * @ version 1.0 * @ Creation Time: 08:44:26 */public class FirstAction {public String <span style = "color: # ff0000;"> firtstMethod </span> () {System. out. println ("hello word, this my first Struts! "); Return" hello ";}}

5. Create a New View/hello/welcome. jsp file under WebRoot.

The Code of welcome. jsp is as follows:

<pre name="code" class="html"><%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%><%String path = request.getContextPath();String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">



6. Create a struts. xml file under src

The Code is as follows:

<?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="/<span style="color:#3333ff;">test</span>" extends="struts-default"><action name="<span style="color:#3333ff;">hello</span>" class="cn.wwh.www.struts.FirstAction"method="<span style="color:#ff0000;">firtstMethod</span>"><result name="hello" type="redirect"><param name="location">/views/hello/welcome.jsp</param></result></action></package></struts>
7. deploy it in tomcat

Enter http: // localhost: 8080/Exercise3/test/hello. action in the browser.

The address bar is changed because the redirect (redirection) method is used in the configuration file.

Result chart:



Note ):

1. The jar package cannot be imported repeatedly. Otherwise, a jar conflict occurs. Due to various jar packages, this exception occurs when tomcat is started.

2. The access address entered in the browser is incorrect. This address combination is related to the namespace and action name in the struts. xml file.

General access method:

Http: // ip: port/contextPath/namespace/actionName [. action]






Steps for developing java web in struts2

1. Build a project
2. Import package
3. Configure web. xml
4. Create an action class
5. Configure struts. xml
6. Page

Development steps of Struts2 and hibernate

Hibernate acts as the interaction of the underlying domain database. In the development step, the ORmapping relationship is established first, then the injection is performed, and the SQL spelling based on the business logic is performed.

As the display layer, Struts2 mainly controls the data returned in the action. What data is returned if you want to display the content on the page. The tag library of struts2 is available and optional, depending on your habits

The two frameworks are best attached to the spring framework. According to the MVC structure, hibernate is responsible for data interaction at the Model layer, struts2 is responsible for display effect control at the View layer, and spring is responsible for processing the Controller of the business logic, inject dependencies. If this structure is used, you must first set up the framework and compile the configuration file ....

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.