0
点赞
收藏
分享

微信扫一扫

使用新版eclipse创建struts2项目

at小涛 2022-04-21 阅读 374

安装JDK、Tomcat、Eclipse

Tomcat下载地址:https://tomcat.apache.org/download-90.cgi
配置系统环境变量,在系统变量中新建并编辑,输入变量名“CATALINA_HOME”,变量值为Apache
Tomcat解压后放置的路径。
Eclipse下载地址:https://www.eclipse.org/downloads/

配置Eclipse

在这里插入图片描述

导入项目

File-Import
在这里插入图片描述在这里插入图片描述

新建项目

Dynamic Web Project

在这里插入图片描述

login.jsp

新版没有Webcontent文件夹的,直接在webapp文件夹下新建文件

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!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=UTF-8">
<title>Insert title here</title>
</head>
<body>
<form action="mylogin_login" method="post">
<table>
<tr>
<td>account:</td>
<td><input type="text" name="account"></td>
</tr>
<tr>
<td>password:</td>
<td><input type="password" name="password"></td>
</tr>
<tr>
<td colspan="2"><input type="submit" value="login"></td>
</tr>
</table>
</form>
</body>
</html>

导入jar包

放到项目目录/src/main/webapp/WEB-INF/lib/ 即可

新建包

在这里插入图片描述
“src/main/java”-New-Package-org.danni.web.action

LoginAction.java

package org.danni.web.action;


public class LoginAction{
    private String account;
    private String password;

    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 login(){
        //如果账号是lili,密码是123456就可以去index页面
        if("lili".equals(account) && "123456".equals(password)){
            return "loginSuccess";
        }
        //否则继续回到login页面
        return "login";
    }
}

struts.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd" id="WebApp_ID" version="4.0">
  <display-name>struts2-stu</display-name>
  
	<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>login.jsp</welcome-file>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.jsp</welcome-file>
    <welcome-file>default.htm</welcome-file>
  </welcome-file-list>
</web-app>

在这里插入图片描述

运行项目

在这里插入图片描述
在这里插入图片描述
下载地址:https://download.csdn.net/download/zycdn/85194200

举报

相关推荐

0 条评论