如何在jsp中获取未选中的复选框值?

时间:2019-03-06 17:40:20

标签: html jsp

我正在设计一个考勤系统。在考勤页面上,有卷号,名称和礼物(这是一个复选框)。现在我要做的是,如果选中此复选框,它将更新我的出勤表中的出勤和总计字段。如果未选中,则只会更新总计字段。 如果未选中它,我将面临一个问题,否则它将在表中更新。

att.jsp

extension CIFilter {
func colorCubeFilterFromLUT(name : String) -> CIFilter? {
    print("Filter: func colorCubeFilterFromLUT")

    let size = 64

    let name1 = "LUT2.png"
    let lutImage    = UIImage(named: name1)!.cgImage
    let lutWidth    = lutImage!.width
    let lutHeight   = lutImage!.height
    let rowCount    = lutHeight / size
    let columnCount = lutWidth / size

    if ((lutWidth % size != 0) || (lutHeight % size != 0) || (rowCount * columnCount != size)) {
        print("iInvalid colorLUT %@\(name1)")
        return nil
    }

    let bitmap  = CIFilter.getBytesFromImage(from: lutImage)
    let floatSize = MemoryLayout<Float>.size

    let cubeData = UnsafeMutablePointer<Float>.allocate(capacity: size * size * size * 4 * floatSize)
    var z = 0
    var bitmapOffset = 0

    for _ in 0 ..< rowCount {
        for y in 0 ..< size {
            let tmp = z
            for _ in 0 ..< columnCount {
                for x in 0 ..< size {

                    let alpha   = Float(bitmap![bitmapOffset]) / 255.0
                    let red     = Float(bitmap![bitmapOffset+1]) / 255.0
                    let green   = Float(bitmap![bitmapOffset+2]) / 255.0
                    let blue    = Float(bitmap![bitmapOffset+3]) / 255.0

                    let dataOffset = (z * size * size + y * size + x) * 4

                    cubeData[dataOffset + 3] = alpha
                    cubeData[dataOffset + 2] = red
                    cubeData[dataOffset + 1] = green
                    cubeData[dataOffset + 0] = blue
                    bitmapOffset += 4
                }
                z += 1
            }
            z = tmp
        }
        z += columnCount
    }

    let colorCubeData = NSData(bytesNoCopy: cubeData, length: size * size * size * 4 * floatSize, freeWhenDone: true)

    // create CIColorCube Filter
    let filter = CIFilter(name: "CIColorCube")
    filter?.setValue(colorCubeData, forKey: "inputCubeData")
    filter?.setValue(size, forKey: "inputCubeDimension")

    return filter
}

class func getBytesFromImage(from image:CGImage?) -> [UInt8]?{
    print("Filter: func getBytesFromImage")
    var pixelValues: [UInt8]?
    if let imageRef = image {
        let width = Int(imageRef.width)
        let height = Int(imageRef.height)
        let bitsPerComponent = 8
        let bytesPerRow = width * 4
        let totalBytes = height * bytesPerRow

        let bitmapInfo = CGImageAlphaInfo.premultipliedLast.rawValue | CGBitmapInfo.byteOrder32Little.rawValue
        let colorSpace = CGColorSpaceCreateDeviceRGB()
        var intensities = [UInt8](repeating: 0, count: totalBytes)

        let contextRef = CGContext(data: &intensities, width: width, height: height, bitsPerComponent: bitsPerComponent, bytesPerRow: bytesPerRow, space: colorSpace, bitmapInfo: bitmapInfo)
        contextRef?.draw(imageRef, in: CGRect(x: 0.0, y: 0.0, width: CGFloat(width), height: CGFloat(height)))

        pixelValues = intensities
    }
    return pixelValues!
}

test1.jsp

<FORM method="POST" ACTION="test1.jsp">
  <table>
    <% for(int i=0;i<results.size();i++){%>
    <tr>
      <td>
        <%=results.get(i)%>
      </td>
      <td>
        <%=name1.get(i)%>
      </td>
      <td>
        <input TYPE=checkbox name=sports VALUE=<%=results.get(i)%>>
      </td>
      <td>
        Present
      </td>

    </tr>

    <% } %>

  </table>
  <br> <INPUT TYPE=submit name=submit Value="Submit">
</FORM>

1 个答案:

答案 0 :(得分:0)

您必须将所有运动项目的列表(从results的{​​{1}}传递到att.jsp作为会话属性,然后遍历全部运动,并对已检查的情况和未检查的情况使用不同的更新语句。

旁注:

  1. 从不使用字符串连接从用户输入创建SQL命令,即使在学校项目中也是如此。这使您的代码容易受到SQL Injection的攻击。请改用PreparedStatement

  2. 请勿使用脚本(test1.jsp),而应使用JSTL

  3. 请勿将业务逻辑和/或SQL代码放入JSP,请使用Model-View-Controller体系结构。