Write a program for getting started with struts2, which has been wrong since. The Action Code is as follows:
}Package cn.edu. qust. struts. action; <br/> Import COM. opensymphony. xwork2.actionsupport; <br/> public class firstaction extends actionsupport {<br/> private int operand1; <br/> private int operand2; <br/> private int sum = 0; <br/> Public int getoperand1 () {<br/> return operand1; <br/>}< br/> Public void setoperand1 (INT operand1) {<br/> system. out. println (operand1); <br/> This. operand1 = operand1; <br/>}< br/> Public int getoperand2 () {<br/> return operand2; <br/>}< br/> Public void setoperand2 (INT operand2) {<br/> system. out. println (operand2); <br/> This. operand2 = operand2; <br/>}< br/> Public int getsum () {<br/> system. out. println (SUM); <br/> sum = operand1 + operand2; <br/> system. out. println (SUM); <br/> return sum; <br/>}< br/> Public String execute () throws exception {<br/> If (getsum ()> = 0) {<br/> return "success"; <br/>}else {<br/> return "failure "; <br/>}< br/>
The struts configuration is as follows:
<? XML version = "1.0" encoding = "UTF-8"?> <Br/> <! Doctype struts public "-// Apache Software Foundation // DTD struts configuration 2.1 // en" "http://struts.apache.org/dtds/struts-2.1.dtd"> <br/> <struts> <br/> <package name =" struts2 "extends =" struts-Default "> <br/> <action name =" sum "class =" cn.edu. qust. struts. action. firstaction "> <br/> <result name =" success ">/positive. JSP </result> <br/> <result name = "failure">/negative. JSP </result> <br/> </Action> <br/> </package> <br/> </struts> <br/>
The Web. XML Code is as follows:
<? XML version = "1.0" encoding = "UTF-8"?> <Br/> <web-app version = "2.5" <br/> xmlns = "http://java.sun.com/xml/ns/javaee" <br/> xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" <br/> xsi: schemalocation = "http://java.sun.com/xml/ns/javaee <br/> http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <br/> <filter-Name> struts2 </filter-Name> <br/> <Filter -Class> <br/> Org. apache. struts2.dispatcher. ng. filter. strutsprepareandexecutefilter <br/> </filter-class> <br/> </filter> <br/> <filter-mapping> <br/> <filter-Name> struts2 </ filter-Name> <br/> <URL-pattern>/* </url-pattern> <br/> </filter-mapping> </Web-app> <br/>
The sum. JSP code is as follows:
<% @ Page Language = "Java" Import = "Java. util. *" pageencoding = "UTF-8" %>
<% @ Taglib prefix = "S" uri = "/Struts-tags" %>
<! Doctype HTML public "-// W3C // dtd html 4.01 transitional // en">
<HTML>
<Head>
<Title> input Operations </title>
</Head>
<Body>
This is my JSP page. <br>
Algebra and
<Br/>
<S: Form Action = "sum">
<S: textfield name = "operand1" label = "operand 1"> </S: textfield>
<S: textfield name = "operand2" label = "operand 2"> </S: textfield>
<S: Submit value = "Algebra and"/>
</S: Form>
</Body>
</Html>
There are also positive. jsp and negative. jsp.
Enter 12 and 1 in the sum. jsp interface to enter the positive. jsp interface. However, the wonderful thing is that the input-12 and 1 are also the interfaces generated by positive. jsp. This is depressing.
It's just 15:10:47. The code public class firstaction extends actionsupport has an automatic warning. @ suppresswarnings ("serial") is added according to the automatic prompt "). And then re-release. It turned out to be successful!
I think it may be the relationship between automatically added code. I removed the automatically added code and tried again. It turned out to be a result. This is depressing. But now the code is correct. I am also sleepy. I went to bed. I wrote the question here first, and I thought I was studying it later.
Insert time 15:17:08