?
Struts eight steps doing tutorial: struts let me try to know you
(Jiang Yuandong China Netcom Group System Integration Company 2004-08-20 Original Jiang__30@163.com)
Abstract: This article belongs to the initial tutorial, but more introduces Struts's technical characteristics, the purpose is to help people who don't know Struts quickly start. Don't look at it. Combined with JBuilder X, WebLogic Server 8.1 explained in detail the process of using the Struts framework.
[Reference Online Article Some Content] Struts is an enterprise-level web application development framework for source code. Its design is to reduce the burden on the construction enterprise web application as a whole. Struts is the source code open software developed under Jakarta project, consisting of a series of framework classes, auxiliary classes, and custom JSP tag libraries, positioning J2EE applications based on Model 2 design mode. The Model 2 system is an application of the MVC-View-Controller system. In the MVC system, the data model (Model), the representation, and control logic (Controller) are separate components, but they can communicate with each other. The Struts is trying to reduce the burden of constructor-level web applications as a whole, and provide internationalization and database connection support. The STRUTS system can be seen as two relatively independent parts: the first part is the Struts API, used to support the Struts application components; the second part is the Struts JSP tag library, four tags of HTML, Bean, Logic and Template composition. Two parts of Struts have their own different users. For items, the same user may use these two parts at the same time;
Prerequisites using this tutorial: JBuilderx, WebLogic is already configured. Can start running normally.
Our courses have begun:
Be a simple application, including a landing page: login.jsp (user name is: aaa password: is BBB), an actionform, an action, a page successfully jumped page: OK.JSP, failed jump page: error. JSP.
Step 1: Open JBuilderx, create a project strutsdemo as shown below. Click Finish directly.
Step 2: Create WAR Package, File -> New -> Web -> WebModule
Point OK.
Click Next, Name Enter WebDemo, and: Build Web Archive: Selecting WHEN Building Project Or Module. (Compilation Engineering or Module is also compiling WAR packets to make changes to synchronize). Other defaults.
Point next, select struts1.1 as shown below:
Point Finish, the picture is as follows:
Step 3: Create a JSP page.
(You can convert the JSP page that has been designed to support Struts1.1, that is, supporting the Taglib tag) as shown below:
But we have no web pages at present, but first create an actionform. MyActionform.
Step 4: Create an actionform. MyActionform.
File- New -Web - ActionForm. As shown below:
Point OK
Change ActionForm: Change to MyActionForm. Other default, as shown below:
Click Next, add two form fields, user names, passwords. Username, Password. As shown below: Point Add Add 2 tables:
In addition, the Add From JSP button can extract the form field from the already existing JSP.
Point next, appear as follows:
Everything defaults, point finish. The following screen appears:
JBuilder automatically generated struts-config.xml is as follows:
The ActionForm code generated by JBuilderx is as follows:
Package strutsdemo;
Import org.apache.struts.action. *; import javax.servlet.http. *;
public class MyActionForm extends ActionForm {private String passWord; private String userName; public String getPassWord () {return passWord;} public void setPassWord (String passWord) {this.passWord = passWord;} public String getUserName () {return userName;} public void setUserName (String userName) {this.userName = userName;} public ActionErrors validate (ActionMapping actionMapping, HttpServletRequest httpServletRequest) {/ ** @ todo:. finish this method, this is just the skeleton * / return null;} public void reset ActionMapping ActionMapping, httpservletRequest httpservletRequest) {}}
Step 5: Complete the work that is not completed in the third step, create login.jsp.
FILE-New-Web-JSP from ActionForm.
Point OK.
Change the unsP1 to: login.jsp
Select Actionform Class, click on the button next to the Actionform [...], select ActionForm, appears as follows:
Find the package: MyActionform under Strutsdemo, point OK. Enter: / myction in Action Path: / MyAction
Point Next
Everything is default, point finish.
Change the part of login.jsp changes (Special attention, here is /myaction.do):
The username and password are changed above (it is PASSWORD). The red part is changed.
Also change one:
Name = "form1" action = "/ myaction.do" type = "strutsdemo.myactionform" method = "post">
The red part is new.
will
JBuilder Generated Struts JSP for Actionform StrutsDemo.myactionform
change to:
My first Struts experience, user landing
As shown below:
Create OK.JSP and Error.jsp.
File - New - Web - JavaServer Page.
Point Finish. Error.jsp creates the same.
Modify OK.JSP
JBuilder Generated JSP
change to:
You are successful! welcome.
Change Error.JSP to:
Your username or password is incorrect!
Step 6, create an action.
File-new -web - action.
Point OK
Change the name of the Action to: MyAction Other default, click Next.
And do the input as shown above. Point Finish.
The following screen appears in Struts Config Editor:
As shown below:
Click Forward to make the following changes:
Click Forward2 to make the following changes:
Finally, as shown below:
Change source file MyAction.java
Package strutsdemo;
Import org.apache.struts.action. *; import javax.servlet.http. *;
public class MyAction extends Action {public ActionForward execute (ActionMapping actionMapping, ActionForm actionForm, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) {/ ** @ todo: complete the business logic here, this is just a skeleton * / MyActionForm myActionForm = (MyActionForm) actionForm. Throw new java.lang.unsupportedOperationException ("Method Perform () Not Yet Implement.");}}
change to:
Package strutsdemo;
Import org.apache.struts.action. *; import javax.servlet.http. *;
public class MyAction extends Action {public ActionForward execute (ActionMapping actionMapping, ActionForm actionForm, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) {/ ** @ todo: complete the business logic here, this is just a skeleton * / MyActionForm myActionForm = (MyActionForm) actionForm. ; // Get username String username = myActionform.getusername () by login.jsp, password string pass = myActionform.getPassword (); string target; // Define Steering / / Execute the logical part IF (username.equalsignorecase ("jyd") && pass.equals ("12345")) {target = "ok"; // Go to ok.jsp // can pass the httpservletRequest.setttribute ("" "," Landing Success ");} else {target =" error "; // Go to Error.jsp // You can pass the httpservletRequest.setttribute (" Status "," Landing Failed ") by httpservletRequest.SetaTribute (" STATUS "," login failed ");} returnctionmapping. Findforward (Target);
// throw new java.lang.unsupportedOperationException ("Method Perform () Not Yet Implement.");}}
?
Step 7: Compilation Project
Start WebLogic Server 8.1
Configured, JBuilderx's engineering properties, Project Properties servers are WebLogic Server 8.x
Deploy: WebDemo.war
Let's take a look at the overall performance of your computer, my computer PIII, 256M memory, from compiling to deployment success 4 minutes.
The above screen appears, indicating that the deployment is successful. If you go wrong, please see the error message and check the above steps, change Rebuild, RedEploy.
Step 8: Test (guaranteed WebLogic Server has been running)
Enter: http://127.0.0.1: 7001 / WebDemo / login.jsp
Enter your username: JYD password: 12345
Press Submit Submit.
Username: TYU Password: Enter 123
Press Submit Submit.
This Struts initially understands the end.