码迷,mamicode.com
首页 > 编程语言 > 详细

java学习笔记 (1) —— Strut2.3.24环境搭建

时间:2016-03-02 23:34:29      阅读:213      评论:0      收藏:0      [点我收藏+]

标签:

1、打开MyEclipse,添加WebProject,名称为testStruts2

2、配置Tomcat环境。

  1) 在窗口——首选项——MyEclipse——Servers下找到Tomcat6.x

  2) 选择Enable、浏览找到本机Tomcat6文件位置

  3) 找到Tomcat——conf——server.xml文件、在</Host>结束标签前添加

<Context path="/testStruts2" docBase="E:\software\MyEclipseWorkSpaces\testStruts2\WebRoot" reloadable="true" />

3、引入jar包

技术分享

4、配置web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" 
    xmlns="http://java.sun.com/xml/ns/j2ee" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
    http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
        <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>
</web-app>
        

5、在src路径下建立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>
        <package name="testStruts2" extends="struts-default" namespace="">
            <action name="login" class="com.test.action.LoginAction">
                <result name="success">/result.jsp</result>
            </action>
     </package>
    </struts>

6、在src路径下建立类文件

package com.test.action;

import com.opensymphony.xwork2.ActionSupport;

public class LoginAction extends ActionSupport
{
    private static final long serialVersionUID = -74906200993380354L;
    
    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
    {
        return "success";
    }
}
    

7、在WebRoot路径下新建login.jsp、result.jsp进行测试

/**
* login.jsp
*/
  <form action="login" method="post" > 
      username:<input type="text" name="username"><br>
      password:<input type="text" name="password">
  
  <input type="submit" value="submit">
  </form>

/**
* result.jsp
*/
    username:${requestScope.username }<br>
    password:${requestScope.password }

 

java学习笔记 (1) —— Strut2.3.24环境搭建

标签:

原文地址:http://www.cnblogs.com/cklovefan/p/5236701.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!