struts2框架基础web环境搭建

迷南。 2022-06-03 03:45 344阅读 0赞

jar包导入:http://pan.baidu.com/s/1dFBd5Dn
Struts2 开发步骤。
第一步:导入相关struts2的jar包
jar包

第二步:在web.xml 添加过滤器来注册struts2

  1. <!-- 配置struts2过滤器 -->
  2. <filter>
  3. <filter-name>struts2</filter-name>
  4. <filter-class>
  5. org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter
  6. </filter-class>
  7. </filter>
  8. <filter-mapping>
  9. <filter-name>struts2</filter-name>
  10. <url-pattern>/*</url-pattern>
  11. </filter-mapping>

第三步:创建Action,继承com.opensymphony.xwork2.ActionSupport。

  1. package com.dx.action;
  2. import com.opensymphony.xwork2.ActionSupport;
  3. public class LoginAction extends ActionSupport{
  4. private static final long serialVersionUID = 1L;
  5. private String name;
  6. private String password;
  7. public String getName() {
  8. return name;
  9. }
  10. public void setName(String name) {
  11. this.name = name;
  12. }
  13. public String getPassword() {
  14. return password;
  15. }
  16. public void setPassword(String password) {
  17. this.password = password;
  18. }
  19. public String execute()throws Exception{
  20. return "success";
  21. }
  22. }

第四步:创建struts.xml文件配置action

  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.5//EN" "http://struts.apache.org/dtds/struts-2.5.dtd">
  3. <struts>
  4. <package name="default" extends="struts-default">
  5. <action name="login" class="com.dx.action.LoginAction">
  6. <result name="success">success.jsp</result>
  7. </action>
  8. </package>
  9. </struts>

第五步:启动服务器。

发表评论

表情:
评论列表 (有 0 条评论,344人围观)

还没有评论,来说两句吧...

相关阅读