Java Servlet jsp to get the value on the selection box

jsp code

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
 <form method="post" action="ServletDemo"><!-- 将表单提交到对应的界面 -->
    <input type="checkbox" name="auto">选择框</br> 
  </form>
</body>
</html>

java servlet Code

package com.itzheng.servlet;

import java.io.IOException;
import java.sql.SQLException;

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

import com.itzheng.dao.UserDao;
import com.itzheng.dao.impl.UserDaoImpl;
import com.itzheng.domain.UserBean;

/**
 * Servlet implementation class LoginServlet
 */
public class LoginServlet extends ServletDemo {

	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		
		try {
			
			String auto = request.getParameter("auto");

				//判断是否选中
				if("on".equals(autologin)) {
					//如果选中执行如下代码
					........
				}
				
				
			
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		

	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}

Released four original articles · won praise 2 · views 90

Guess you like

Origin blog.csdn.net/qq_44757034/article/details/104105020