strust2快速入门

我认为学习一门新技术最快的方法就是,用这门技术做一个简单的完整的实例。下面是我学习Struts2开始时写的一个登陆程序,供学习struts2的新手看到一下。
下面的截图是该应用用到的jar包:
[img]http://dl.iteye.com/upload/attachment/176560/3861abe2-3a8e-3b6f-a0c1-d15d28d4c7f4.jpg[/img]
web.xml的配置:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>

struts.xml的配置:

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>
<package name="strutsTest" extends="struts-default" >
<action name="login" class="cn.edu.hist.action.LoginAction">
<result name="success" >/success.jsp</result>
<result name="error">/error.jsp</result>
</action>
</package>
</struts>

LoginAction.java代码如下:

package cn.edu.hist.action;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.Action;

/**
* Created by IntelliJ IDEA.
* User: jiaxy
* Date: 2009-11-27
* Time: 11:38:55
* DESC:
*/
public class LoginAction implements Action {
private String username;
private String password;

public String getUsername() {
return username;
}

public void setUsername(String username) {
this.username = username;
}

public String getPassword() {
return password;
}

public void setPassword(String password) {
this.password = password;
}

public String execute() throws Exception {
if(getUsername().equals("guojia")&& getPassword().equals("123")){
ActionContext.getContext().getSession().put("username",getUsername());
return "success";
}else{
return "error";
}
}
}

下面是jsp页面:
index.jsp页面内容:

<%--
Created by IntelliJ IDEA.
User: jiaxy
Date: 2009-11-27
Time: 11:32:45
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head><title>测试</title></head>
<body>
<form action="login" method="post">
用户名:<input type="text" size="12" name="username"/><br>
密 码:<input type="password" size="12" name="password"/><br>
<input type="submit" value="提交"/>
</form>
</body>
</html>

success.jsp页面的内容:

<%--
Created by IntelliJ IDEA.
User: jiaxy
Date: 2009-11-27
Time: 14:10:06
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head><title>登陆页面</title></head>

<body>
欢迎,${sessionScope.username},你已成功登陆!

</body>
</html>
微信小程序毕业设计期末大作业项目源码 微信小程序毕业设计期末大作业项目源码 微信小程序毕业设计期末大作业项目源码 微信小程序毕业设计期末大作业项目源码 微信小程序毕业设计期末大作业项目源码 微信小程序毕业设计期末大作业项目源码 微信小程序毕业设计期末大作业项目源码 微信小程序毕业设计期末大作业项目源码 微信小程序毕业设计期末大作业项目源码 微信小程序毕业设计期末大作业项目源码 微信小程序毕业设计期末大作业项目源码 微信小程序毕业设计期末大作业项目源码 微信小程序毕业设计期末大作业项目源码 微信小程序毕业设计期末大作业项目源码 微信小程序毕业设计期末大作业项目源码 微信小程序毕业设计期末大作业项目源码 微信小程序毕业设计期末大作业项目源码 微信小程序毕业设计期末大作业项目源码 微信小程序毕业设计期末大作业项目源码 微信小程序毕业设计期末大作业项目源码 微信小程序毕业设计期末大作业项目源码 微信小程序毕业设计期末大作业项目源码 微信小程序毕业设计期末大作业项目源码 微信小程序毕业设计期末大作业项目源码 微信小程序毕业设计期末大作业项目源码 微信小程序毕业设计期末大作业项目源码 微信小程序毕业设计期末大作业项目源码 微信小程序毕业设计期末大作业项目源码 微信小程序毕业设计期末大作业项目源码 微信小程序毕业设计期末大作业项目源码 微信小程序毕业设计期末大作业项目源码 微信小程序毕业设计期末大作业项目源码
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值