JBoss-IDE 1.2.2 Introduction (Struts) 2

zhaozj2021-02-16  62

JBoss-Ide 1.2.2 Introduction (Struts) 2:

step:

5. We will have two files after completion, first do Computeform, in Package Explorer expansion 'src' -> 'tutorial.web', double click on 'Computeform', in the right hand side window Computeform's 'public class computeform''s Comment Hit '@', then wait for a while, I can see the struts form template just entered. After selecting it, press Enter, JBoss-IDE will automatically help us fill in the desired template, it is really easy!

Then you can delete 'extends' and 'IMPLEMENTS', now we don't need, only left 'name', fill in 'name = "computeform"', and we will check the input information, so in the Comment after Num Attribute Together with'@struts.validator type = "required, integer", the detailed staff is as follows:

Package tutorial.Web;

Import org.apache.struts.validator.validatorform;

/ **

* @Author patrick.ip

*

* @ Struts.form name = "computeform"

* /

Public Class Computeform Extends ValidatorForm

{

Private string num;

/ **

* Sets the query attribute of the computeform object

*

* @ Struts.validator type = "Required, INTEGER"

* /

Public void setnum (string num) {

THIS.NUM = NUM;

}

Public string getnum () {

Return Num;

}

}

ComputeAction is also similar, the program is as follows:

Package tutorial.Web;

Import java.io.ioException;

Import org.apache.struts.Action.action;

Import org.apache.struts.Action.actionForward;

Import org.apache.struts.action.actionmapping;

Import org.apache.struts.Action.actionform;

Import javax.servlet.servletException;

Import javax.servlet.http.httpservletRequest;

Import javax.servlet.http.httpservletResponse;

/ **

* @Author patrick.ip

*

* @ Struts.Action name = "computeform"

* Path = "/ computefibo"

* Scope = "request"

* Validate = "true"

* Parameter = ""

* INPUT = "/ index.jsp"

*

* @ Struts.Action-forward name = "Success"

* Path = "/ compute" * /

Public class computeaction extends action {

Public ActionForward Execute (ActionMapping Mapping, Actionform Form, HttpServletRequest Request, HttpservletResponse Response)

THROWS IOException, servletexception {

Computeform cf = (computeform) Form;

String Num = Request.getParameter ("NUM");

Request.getations (). SetAttribute ("NUM", NUM);

Return mapping.findforward ("Success");

}

}

Then we modify the dopost method in the ComputeServlet:

Try {

Fibo bean = home.create ();

INT LIMIT = 0;

String value = Request.getParameter ("limit");

// address by PAT

IF ((NULL == Value) || ("" .Equals (value))) {

Value = (string) Request.getSession (). GetAttribute ("NUM");

}

IF (value! = null) {

Try {

Limit = integer.parseint (value);

}

Catch (Exception E) {

}

}

Last Compile Project, right click Tutorial Project -> 'Build Project'

转载请注明原文地址:https://www.9cbs.com/read-21985.html

New Post(0)