Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example Analysis of Struts configuration Test developed by MyEclipse

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces MyEclipse Struts configuration test sample analysis, has a certain reference value, interested friends can refer to, I hope you read this article after a lot of gains, the following let Xiaobian take you to understand.

MyEclipse Struts development environment required: JDK 5.0; Eclipse 3.1M7; MyEclipse 3.84; Tomcat 5.0.28

MyEclipse Development Struts Introduction:

This text focuses on developing a simple user login snippet using MyEclipse's Struts Designer (graphical development environment).

Mainly includes 2 JSP files, an ActionForm, an Action and other

userLogin.jsp userLoginSuccess.jsp

UserLoginForm.java (ActionForm, for user submissions)

UserLoginAction.java (Action, simple handling of user login events)

So that's a brief introduction to MyEclipse Struts development, let's get started:

First, we create a J2EE web project, as shown in Figure 1:

Click next,Project name Enter LoginDemo, the rest remain default, click finish.

In package explorer, you can see our project, and then add the Struts framework necessary files to this project. Right click on our project name and select MyEclipse--> Add Struts Capabilities... Pop-up dialog Figure 2:

Struts config path is our struts configuration file, URL pattern we choose *.do, Default application resource is our default resource file place, you can choose its storage location, we keep the default here. After clicking Finish, the project structure looks like Figure 3:

Let's start with our example. First modify the/WEB-INF/web.xml file and add a tag library to it (found in use, you can succeed without adding it. But to keep the book consistent, add security. hoho~~) Add the following code to/webapp above:

﹤taglib﹥ ﹤taglib-uri﹥/tags/struts-html﹤/taglib-uri﹥ ﹤taglib-location﹥/WEB-INF/struts-html.tld﹤/taglib-location﹥ ﹤/taglib﹥ ﹤taglib﹥ ﹤taglib-uri﹥/tags/struts-bean﹤/taglib-uri﹥ ﹤taglib-location﹥/WEB-INF/struts-bean.tld﹤/taglib-location﹥ ﹤/taglib﹥ ﹤taglib﹥ ﹤taglib-uri﹥/tags/struts-logic﹤/taglib-uri﹥ ﹤taglib-location﹥/WEB-INF/struts-logic.tld﹤/taglib-location﹥ ﹤/taglib﹥

When finished, open the struts-config.xml file and click Design in the lower left corner of the interface to enter the visual design interface. There's no note on the right Palette :) Click on it and let's start our jsp page design. Let's create userLoginSuccess.jsp file first, why create this one first? We'll see later. In myeclipse, we can build our Action,ActionForm,Jsp files at once (create three associated files later).

Click the Create JSP File icon on the Palette panel to pop up the Create JSP File panel. Figure 4:

Enter userLoginSuccess.jsp in File Name, select Template to use 2] Standard JSP using Struts 1.1, click Finish to finish.

When this is done, the struts-config.xml file is automatically updated and the newly created JSP module appears on the visualization world. The newly created jsp file is also opened.

Overwrite all < %@ taglib... For us to start with what is defined in/WEB-INF/web.xml:

﹤%@ taglib uri="/tags/struts-html" prefix="html"%﹥ ﹤%@ taglib uri="/tags/struts-bean" prefix="bean"%﹥ ﹤%@ taglib uri="/tags/struts-logic" prefix="logic"%﹥

Then add in body/body:

Hello ﹤bean:write name="userName" scope="request" /﹥ .

Here, the attribute userName in the request is output on the page, so later we will set a related attribute in UserLoginAction after successful login.

OK, let's start with the design of our *** three files. In the Design mode of Struts-config.xml, right-click in the blank area of the drawing, select New --> New Form, Action and JSP to pop up the Options Panel of ActionForm, and we input the relevant values according to the figure. Figure 5:

On the Optional Details Form Properties tab, click add to add values for the ActionForm. In this login example, two attributes userName and password will be added, Figure 6:

When adding password, note that the JSP input type drop-down box selects password.

Once this is done, we will complete the ActionForm design.

Next select the JSP tab of Optional Details and we check Create JSP form? This step myeclipse will create a simple login page for us to interact with the user. Keep the contents as shown in Figure 7. Figure 7:

Because we are only demonstrating a simple login fragment, we do not need to verify whether the user information is legal, so remove the new method of the method tab of Option Details, as shown in Figure 8:

Click Next to enter the Action Options Panel. Deselect Validate Form in the Form tab of Option Details, as shown in Figure 9:

Then click Add on the Forwards tab to add the pages returned successfully and unsuccessfully. Figure 10:

Click Finish to finish. In Struts-config.xml's Design, you can see Figure 11:

***, Simply modify userLogin.jsp, change all < %@ taglib... % Replace with:

﹤%@ taglib uri="/tags/struts-html" prefix="html"%﹥ ﹤%@ taglib uri="/tags/struts-bean" prefix="bean"%﹥

Modify the execute fragment in UserLoginAction as follows, Figure 12:

OK, done... The following is a test on the summer program...

Just like adding Struts framework to a project, right-click on the project name and select MyEclipse --> Add and Remove Project development.

On the pop-up dialog box, click Add. On the pop-up New Deployment dialog box, select Tomcat5 for Server, and click Finish to complete deployment, as shown in Figure 13:

Open in your browser: 127.0.0.1:8080/LoginDemo/userLogin.jsp

Enter password 123456, username EricHe. Show success:

If you type incorrectly, or do not enter, there is no reflection back to the current login page (because we do not set the error message).

Thank you for reading this article carefully. I hope that the article "MyEclipse Development Struts Configuration Test Sample Analysis" shared by Xiaobian will be helpful to everyone. At the same time, I hope that everyone will support it and pay attention to the industry information channel. More relevant knowledge is waiting for you to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report