在eclipse安装和创建maven demo项目

1、Eclipse中配置maven  

1、eclipse4.0以上不用导入maven插件(4.0以下导入重启)在这里maven的环境变量jdk的环境变量要配置好;保证eclipse中jre

的指向和maven一直

 

 

2、选择配置添加本地的maven

  

 

 

3、设置maven的usersettings

(在这里选择的是本地仓库中的settings,避免maven升级时导致的settins发生改变)

 

2、创建maven项目

右键new project ->maven project->next->选择默认 ->输入坐标信息->finish

转载于:https://www.cnblogs.com/404code/p/10185858.html

这里给出一个使用 Maven 和 SpringMVC 实现登录页面的示例代码,你可以在 Eclipse创建一个 Maven 项目,然后按照以下步骤进行操作: 1. 在 pom.xml 文件中添加 SpringMVC 和 JSP 相关依赖: ```xml <dependencies> <!-- SpringMVC --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>5.3.9</version> </dependency> <!-- JSP --> <dependency> <groupId>javax.servlet</groupId> <artifactId>jstl</artifactId> <version>1.2</version> </dependency> <dependency> <groupId>org.apache.tomcat.embed</groupId> <artifactId>tomcat-embed-jasper</artifactId> <version>9.0.50</version> </dependency> </dependencies> ``` 2. 创建一个 UserController 类,在其中添加登录方法: ```java package com.example.demo.controller; import javax.servlet.http.HttpServletRequest; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; @Controller public class UserController { @RequestMapping(value = "/login", method = RequestMethod.GET) public String showLoginPage() { return "login"; } @RequestMapping(value = "/login", method = RequestMethod.POST) public String handleLoginRequest(HttpServletRequest request) { String username = request.getParameter("username"); String password = request.getParameter("password"); if ("admin".equals(username) && "123456".equals(password)) { return "home"; } else { return "login"; } } } ``` 3. 在 src/main/resources 目录下创建 SpringMVC 配置文件 springmvc.xml,并配置视图解析器和资源路径: ```xml <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/WEB-INF/views/" /> <property name="suffix" value=".jsp" /> </bean> <mvc:resources mapping="/assets/**" location="/assets/" /> ``` 4. 在 src/main/webapp/WEB-INF/views 目录下创建 login.jsp 和 home.jsp 两个 JSP 页面,用于显示登录表单和登录成功页面,代码如下: login.jsp: ```html <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <html> <head> <title>Login Page</title> </head> <body> <h1>Login Page</h1> <form action="login" method="post"> <table> <tr> <td>Username:</td> <td><input type="text" name="username"></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> ``` home.jsp: ```html <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <html> <head> <title>Home Page</title> </head> <body> <h1>Welcome <%=request.getParameter("username") %>!</h1> <a href="<c:url value="/login" />">Logout</a> </body> </html> ``` 5. 在 src/main/webapp 目录下创建 assets 目录,并将样式表和图片等静态资源放到该目录下。 6. 配置 Tomcat 服务器并启动项目,在浏览器中访问 http://localhost:8080/login 即可看到登录页面。输入正确的用户名和密码后,将跳转到 home 页面,显示欢迎信息。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值