第一个Struts2程序,helloworld

第一个struts2程序,整了将近一天,好激动。嘿嘿

web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
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">

<!-- 配置Struts 2框架的核心Filter -->
<filter>
<!-- 配置Struts 2框架的核心Filter的名字 -->
<filter-name>struts</filter-name>
<!--配置Struts 2框架的核心Filter的实现类 -->
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>

<!-- 配置Filter拦截的URL -->
<filter-mapping>
<filter-name>struts</filter-name>
<!-- 配置struts2的核心 FilterDispatcher拦截所有用户请求-->
<url-pattern>/*</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>s2impl/login.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.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd">

<struts>
<constant name="struts.devMode" value="true"/>
<constant name="struts.locale" value="zh_CN"/>
<constant name="struts.il8n.encoding" value="gb2312"/>

<package name="helloworld" namespace="" extends="struts-default">
<action name="helloworldAction" class="cn.javass.hello.Struts2impl.action.HelloWorldAction">
<result name="toWelcome">/s2impl/welcome.jsp</result>
</action>
</package>

</struts>


login.jsp
<%@ page language="java" contentType="text/html; charset=gb2312"
pageEncoding="gb2312"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>


<form action="/helloworld/helloworldAction.action" method="post">
<input type="hidden" name="submitFlag" value="login"/>
账号::<input type="text" name="account"><br>
密码::<input type="text" name="password"><br>
<input type="submit" value="提交">
</form>
</body>
</html>


welcome.jsp
<%@ page language="java" contentType="text/html; charset=gb2312"
pageEncoding="gb2312"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>


欢迎账号为<s:property value="account"/>的朋友来访

</body>
</html>


HelloWorldAction.java
package cn.javass.hello.Struts2impl.action;

import com.opensymphony.xwork2.Action;

public class HelloWorldAction implements Action{
private String account;
public String getAccount() {
return account;
}
public void setAccount(String account) {
this.account = account;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getSubmitFlag() {
return submitFlag;
}
public void setSubmitFlag(String submitFlag) {
this.submitFlag = submitFlag;
}
private String password;
private String submitFlag;
public String execute() throws Exception{
System.out.println("用户输入的参数为===account="+account+",password="+password+",submitFlag="+submitFlag);
return "toWelcome";
}

}


这是项目目录结构


[img]http://dl.iteye.com/upload/attachment/0081/9894/f891d75d-f24e-3e6c-bca9-e1e4ff6bc265.gif[/img]
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值