struts2学笔记一 helloworld


一增加struts2功能
1
库ognl-2.6.11
struts2-core-2.0.6
xwork-2.0.1
2web.xml配置struts2的核心filter
 <filter>
        <filter-name>struts2</filter-name>
        <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
    </filter>

 <!-- FilterDispatcher用来初始化struts2并且处理所有的WEB请求。 -->
    <filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

3struts.xml
<struts>
    <package name="lee" extends="struts-default">
        <action name="Login" class="lee.LoginAction">
            <result name="error">/error.jsp</result>
            <result name="success">/welcome.jsp</result>       
        </action>
    </package>
</struts>

二走向
1.login.jsp
<form action="Login.action" method="post">
2.filterDispatcher拦截转发请求(web.xml拦截;struts.xml配置中找对应action)
3action(struts2不再像struts1需要继承一个Action父类;它只是一个包含execute方法的普通Java类)
public class LoginAction implements Action {
 public String execute() throws Exception {
  if (getUsername().equals("pp") && getPassword().equals("911")) {
   ActionContext.getContext().getSession().put("user", getUsername());
   return "success";
  } else {
   return "error";
  }
 }
}
4导航转到对应的页面(根据struts.xml中的配置)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值