免费视频淫片aa毛片_日韩高清在线亚洲专区vr_日韩大片免费观看视频播放_亚洲欧美国产精品完整版

打開APP
userphoto
未登錄

開通VIP,暢享免費(fèi)電子書等14項(xiàng)超值服

開通VIP
2 Struts Hello World Example in Eclipse

Struts Hello World Example in Eclipse

06.13.2012

·                                                               

File Source : http://www.dzone.com/tutorials/java/struts/struts-tutorial/struts-tutorial-using-eclipse-1.html

In this tutorial you will learn howto create a Struts hello world application in eclipse. First create a newproject, go to File->New and select 

DynamicWebProject. 

 
 

Enter the project name and clickthe Finish button.

 
 
Add the following jar files to theWEB-INF\lib directory.

 
 

Right click the src folder andselect New->Package.

 
 
 
 
 
 

Enter the package name as com.vaannila.form and click Finish.

Now right click the newly createdpackage and select New->Class.

 
 

Enter the class name as HelloWorldForm and the superclass name asorg.apache.struts.action.ActionForm and click Finish.

 
 

In the HelloWorldForm class add thefollowing code.

01.package com.vaannila.form;

02. 

03.import org.apache.struts.action.ActionForm;

04. 

05.public class HelloWorldForm extends ActionForm {

06. 

07.private static final long serialVersionUID = -473562596852452021L;

08. 

09.private String message;

10. 

11.public String getMessage() {

12.return message;

13.}

14. 

15.public void setMessage(String message) {

16.this.message = message;

17.}

18.}

In the same way create a newpackage com.vaannila.action and create a HelloWorldAction class extending org.apache.struts.action.Action. Add the following code to theaction class and save it.

 

01.package com.vaannila.action;

02. 

03.import javax.servlet.http.HttpServletRequest;

04.import javax.servlet.http.HttpServletResponse;

05. 

06.import org.apache.struts.action.Action;

07.import org.apache.struts.action.ActionForm;

08.import org.apache.struts.action.ActionForward;

09.import org.apache.struts.action.ActionMapping;

10. 

11.import com.vaannila.form.HelloWorldForm;

12. 

13.public class HelloWorldAction extends Action {

14. 

15.@Override

16.public ActionForward execute(ActionMapping mapping, ActionFormform, HttpServletRequest request, HttpServletResponse response) throwsException {

17.HelloWorldForm hwForm = (HelloWorldForm) form;

18.hwForm.setMessage("Hello World");

19.return mapping.findForward("success");

20.}

21.}

Here we typecast the ActionForm to HelloWorldForm and set the message value.

Add the following entries in the struts-config.xml file.

 

01.<?xml version="1.0" encoding="ISO-8859-1" ?>

02. 

03.<!DOCTYPE struts-config PUBLIC

04."-//Apache Software Foundation//DTD StrutsConfiguration 1.3//EN"

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

06. 

07.<struts-config>

08. 

09.<form-beans>

10.<form-bean name="helloWorldForm"type="com.vaannila.form.HelloWorldForm"/>

11.</form-beans>

12. 

13.<global-forwards>

14.<forward name="helloWorld" path="/helloWorld.do"/>

15.</global-forwards>

16. 

17.<action-mappings>

18.<action path="/helloWorld"type="com.vaannila.action.HelloWorldAction" name="helloWorldForm">

19.<forward name="success" path="/helloWorld.jsp" />

20.</action>

21.</action-mappings>

22. 

23.</struts-config>

Now configure the deploymentdescriptor. Add the following configuration information in the web.xml file.

 

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

02.<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/javaeehttp://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID"version="2.5">

03.<display-name>StrutsExample1</display-name>

04. 

05.<servlet>

06.<servlet-name>action</servlet-name>

07.<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>

08.<init-param>

09.<param-name>config</param-name>

10.<param-value>/WEB-INF/struts-config.xml</param-value>

11.</init-param>

12.<load-on-startup>2</load-on-startup>

13.</servlet>

14. 

15.<servlet-mapping>

16.<servlet-name>action</servlet-name>

17.<url-pattern>*.do</url-pattern>

18.</servlet-mapping>

19. 

20.<welcome-file-list>

21.<welcome-file>index.jsp</welcome-file>

22.</welcome-file-list>

23.</web-app>

When we run the application theindex.jsp page will be executed first. In the index.jsp page we redirect the request to the helloWorld.do URI, which inturn invokes the HelloWorldAction.

 

1.<%@ tagliburi="http://struts.apache.org/tags-logic" prefix="logic" %>

2.<logic:redirect forward="helloWorld"/>

In the action class we return theActionForward "success" which is mapped to the helloWorld.jsp page. In the helloWorld.jsp page we display the "HelloWorld" message.

 

01.<%@taglib uri="http://struts.apache.org/tags-bean"prefix="bean" %>

02.<html>

03.<head>

04.<meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1">

05.<title>Hello World</title>

06.</head>

07.<body>

08.<bean:write name="helloWorldForm" property="message"/>

09.</body>

10.</html>

After creating all the files thedirectory structure of the application looks like this.

 
 

On executing the application the"Hello World" message gets displayed to the user.

 
 

You can download the source code ofthis example by clicking on the Download link below.

Source: Download
War:
 Download

 

本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊舉報(bào)。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
SSH實(shí)現(xiàn)的增刪改查實(shí)例
tomcat的web.xml設(shè)置問題:<servlet-name>Action</servlet-name><url-pattern>*.do的含義
JSP的運(yùn)行內(nèi)幕
學(xué)Struts2從HelloWorld示例開始
Struts 2.0的Action講解
Struts2 初探
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長(zhǎng)圖 關(guān)注 下載文章
綁定賬號(hào)成功
后續(xù)可登錄賬號(hào)暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服