整合Spring2.0 +struts2.0
<?xml?version="1.0"?encoding="UTF-8"?>???
<!DOCTYPE?beans?PUBLIC?"-//SPRING//DTD?BEAN?2.0//EN"?"http://www.springframework.org/dtd/spring-beans-2.0.dtd">???
<beans>???
????<bean?id="helloWorld"?class="com.tianji.test.HelloWorld"></bean>???
</beans>
<!--上面的解释下:在前面说了,这个bean中的ID,必须与struts中的action指定的class值一样,此bean中的class就是你要处理的action类,如果你在action时有传值,则在此bean中加入形如:
<property?name="message">
????<value>i?love?you</value></property>
形式的语句!
?-->
5、写一个action类
HelloWord.java
?2?import?com.opensymphony.xwork2.ActionSupport;????
?3?public?class?HelloWorld?extends?ActionSupport?{????
?4????
?5?????public?static?final?String?MESSAGE?=?"Struts?is?up?and?running?
";?????6????
?7?????public?String?execute()?throws?Exception?{????
?8?????????setMessage(MESSAGE);????
?9?????????return?SUCCESS;????
10?????}????
11????
12?????private?String?message;????
13????
14?????public?void?setMessage(String?message){????
15?????????this.message?=?message;????
16?????}????
17????
18?????public?String?getMessage()?{????
19?????????return?message;????
20?????}????
21?}???
22?
23?
这个不用解释哈!
6、创建HelloWord.jsp
2?<html>???
3?????<head>???
4?????????<title>Hello?World!</title>???
5?????</head>???
6?????<body>???
7?????????<h2><s:property?value="message"?/></h2>???
8?????</body>???
9?</html>??
发布,运行服务器,在浏览器中打开:
http://localhost:8080/love/HelloWorld.action
注意修改上面红色部份!
结果:成功!
Struts is up and running````````