1、概述
2、Struts2开发环境搭建
根据事例选择jar包。
操作小技巧:
将上面jar包统一打成User Library
小结:
3、helloStruts第一个应用程序
创建helloStruts.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>Insert title here hello struts!
修改struts.xml
/helloStruts.jsp
注:注释快捷键(ctrl+shift+/)取消(ctrl+shift+\)删除(ctrl+d)
result:"/"指的是"WebRoot"
namespace:"/"指的是“”中“hello”前的“/”
异常处理:
解释:开发环境(Eclipse indigo版本)不支持将打好的
jar包加入到项目的部署环境中,也就是说,部署时有jar包,但jar包并没有对项目提供支持。办法:
第二个异常:
解释:没有这个action(“/”),配置文件中的action为“/hello”
办法:
尝试:
4、创建Action
普通Action类:
package com.ljb.web.action;public class HelloAction1 { public String execute(){ return "success"; }}
/helloStruts.jsp
<constant name="struts.devMode" value="true" />
这句话的作用:不用更改配置频繁启动服务器实现Action接口类:
package com.ljb.web.action;import com.opensymphony.xwork2.Action;public class HelloAction2 implements Action { @Override public String execute() throws Exception { // TODO Auto-generated method stub return "success"; }}
/helloStruts.jsp
继承ActionSupport类:
package com.ljb.web.action;import com.opensymphony.xwork2.ActionSupport;public class HelloAction3 extends ActionSupport { @Override public String execute() throws Exception { // TODO Auto-generated method stub return "success"; }}
/helloStruts.jsp
执行结果:
5、关联源码
6、小结