7月29日 SSM 周日

本文档提供了一个Java Web应用程序的实例代码,包括了页面跳转、用户登录、文件上传等功能,并展示了如何使用JSP技术和Spring框架进行开发。
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">

    <title>My JSP 'addUser.jsp' starting page</title>

    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">    
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <!--
    <link rel="stylesheet" type="text/css" href="styles.css">
    -->

  </head>

  <body>
    <form action="<%=path%>/add.do" method="post" enctype="multipart/form-data">

    mid:<input type="text" name="mid"><br>
    name:<input type="text" name="name"><br>
    sex:<input type="text" name="sex"><br>
    age:<input type="text" name="age"><br>
    photo:<input type="file" name="tx"><br>
    <input type="submit" value="提交">
    </form>
  </body>
</html>
package com.controller;

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

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

import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.commons.CommonsMultipartFile;

import com.dto.Man;
import com.dto.User;
import com.service.UserService;
import com.util.FileUploadUtils;

@org.springframework.stereotype.Controller
public class Controller {
    @Autowired
    private UserService service;
    @RequestMapping("login")
    public void login(User user,HttpServletResponse response,HttpServletRequest request) throws IOException{
        System.out.println("用户登录"+user);
        System.out.println(request.getContextPath()+"根路径");
        int i = service.login(user);
        if(i>0){
            request.getSession().setAttribute("us", user);
        }
        System.out.println("登录状态"+i);
        response.getWriter().print(i);
    }
    @RequestMapping("logout")
    public String logout(HttpServletRequest request){
        request.getSession().invalidate();
        return "redirect:/toIndex.jsp";
    }
    @RequestMapping("list")
    public String list(HttpServletRequest request,Integer info){
        List<Man> manList = service.findManList();
        request.setAttribute("manList", manList);
        request.setAttribute("info", info);
        return "manList";
    }
    @RequestMapping("add")
    public void add(Man man,HttpServletRequest request,@RequestParam("tx")CommonsMultipartFile photo){
        System.out.println(man);
        if(photo.getSize()>0){
            String photoName = FileUploadUtils.upload(photo, request, "imgs");
            man.setPhoto(photoName);
        }
//      int i = service.add(man);
//      return 0;
    }

}

阁下何不乘风去,扶摇直上九万里
《扶摇》

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值