Spring 第二讲:spring项目结构

一、项目结构

在这里插入图片描述

1、WebContent

在这里插入图片描述

1.1 web.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_3_1.xsd"
	id="WebApp_ID" version="3.1">
	<display-name>demo_back</display-name>
	<!-- 配置SpringMVC前端控制器 -->
	<servlet>
		<servlet-name>mvc</servlet-name>
		<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
		<!-- SpringMVC的配置文件的默认路径是/WEB-INF/${servlet-name}-servlet.xml -->
		<init-param>
			<param-name>contextConfigLocation</param-name>
			<!--<param-value>classpath:springmvc.xml</param-value> -->
			<param-value>classpath:spring/springmvc.xml</param-value>
		</init-param>
		<load-on-startup>2</load-on-startup>
	</servlet>
	<servlet-mapping>
		<servlet-name>mvc</servlet-name>
		<!-- 设置所有以action结尾的请求进入SpringMVC -->
		<url-pattern>*.action</url-pattern>
	</servlet-mapping>
	<context-param>
		<!-- 读取数据库配置文件 -->
		<param-name>contextConfigLocation</param-name>
		<param-value>classpath:spring/application_*.xml</param-value>
	</context-param>
	<listener>
		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
	</listener>
	<welcome-file-list>
		<welcome-file>index.action</welcome-file>
	</welcome-file-list>
</web-app>

1.2 index 和 sys_users_info

存放 jsp 页面

1.3 lib

存放各种 jar 包

1.4 upload

保存图片

2、config

存放配置文件
在这里插入图片描述

3、src

在这里插入图片描述

3.1 common

存放公共通用类,一些时间方法、加密方法、设置 id 方法、String 工具类

3.2 controller

indexController

package com.demo.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.demo.common.ShaEncrypt;
import com.demo.model.SysUsersInfo;
import com.demo.service.SysUsersInfoService;

@Controller
public class indexController {
   

	@Autowired
	private SysUsersInfoService user_service; 
	
	@RequestMapping(value = "login")
	public String login() {
   
		
		return "index/login";
	}
	
	@RequestMapping(value = "check_login")
	public void String(String login,String pwd,HttpServletRequest request,HttpServletResponse response) throws IOException{
   
		PrintWriter out = response.getWriter();
		
		SysUsersInfo u = new SysUsersInfo();
		u.setLoginname(login);
		//密码加密
		String p = ShaEncrypt.shaEncode(pwd);
		u.setPassword(p);
		List<SysUsersInfo> check_login = user_service.select_check_login(u);
		if(check_login.isEmpty()){
   
			out.print("error");
		}else{
   
			String check_user = "";
			for(SysUsersInfo s:check_login){
   
				check_user = s.getCheck_user();
			}
			if(check_user.equals("0")){
   
				request.getSession().setAttribute("loginname", login);
				request.getSession().setMaxInactiveInterval(18200);
				out.print("success");
			}else{
   
				out.print("err");
			}
		}
	}
	
	@RequestMapping(value = "index")
	public String index(HttpServletRequest request){
   
		String loginname = (String) request.getSession().getAttribute("loginname");
		request.setAttribute("loginname", loginname);
		return "index/index";
	}
	
	@RequestMapping(value = "find_info")
	public String find_info(HttpServletRequest request){
   
		String loginname = (String) request.getSessi
  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值