这是我的Java课程
package login.example;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.persistence.Id;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
@WebServlet("/UserOne")
public class UserOne extends HttpServlet {
private static final long serialVersionUID = -7250065889869767422L;
@Id
private long id;
private String name;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public void setId(long id) {
this.id = id;
}
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
PrintWriter out = response.getWriter();
response.setContentType("text/html");
long id = Long.parseLong(request.getParameter("id"));
String name = request.getParameter("name");
// String userRePass = request.getParameter("userRePassWord");
try {
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/any", "root", "jaygurudev1@");
PreparedStatement ps = con.prepareStatement("Select id,name from user where id=? and name=?");
ps.setLong(1, id);
ps.setString(2, name);
ResultSet rs = ps.executeQuery();
// HttpServletRequest request = null;
if (rs.next()) {
HttpSession session = request.getSession(true);
session.setAttribute("id", id);
session.setAttribute("name", name);
ServletContext context = request.getServletContext();
response.setHeader("Cache-control", "no-cache"); // HTTP 1.1
response.setHeader("Cache-control", "no-store");
response.setHeader("Pragma", "no-cache"); // HTTP 1.0
response.setDateHeader("Expire", 0);
RequestDispatcher dispatcher = context.getRequestDispatcher("/admin.jsp");
dispatcher.forward(request, response);
// or you can write whole thing in one line as ........
// getServletContext().getRequestDispatcher("/success").forward(request,
// response);
} else {
// request.setAttribute("wrongUser", userName);
ServletContext context = request.getServletContext();
response.setHeader("Cache-control", "no-cache"); // HTTP 1.1
response.setHeader("Cache-control", "no-store");
response.setHeader("Pragma", "no-cache"); // HTTP 1.0
response.setDateHeader("Expire", 0);
RequestDispatcher dispatcher = context.getRequestDispatcher("/login.jsp");
dispatcher.forward(request, response);
// or you can write whole thing in one line as ........
// getServletContext().getRequestDispatcher("/fail").forward(request,
// response);
}
} catch (SQLException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
这是我的login.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<div style="text-align: center">
<h1>admin login</h1>
<%
response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); // HTTP 1.1
response.setHeader("Pragma", "no-cache"); // HTTP 1.0
response.setDateHeader("Expires", 0); // Proxies.
%>
<form action="/UserOne" method="get">
<label for="id">Id</label> <input name="id" /> <label for="name">Name</label>
<input type="text" name="name" />
<button type="submit">Login</button>
</form>
</div>
</body>
</html>
这是我的管理员。jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.Connection"%>
<%@page import="java.io.IOException"%>
<%@page import="java.io.PrintWriter"%>
<!DOCTYPE html>
<html>
<head>
<style>
body {
background-image: url(/images/admin.jpg);
background-repeat: repeat;
background-size: 640px 640px;
}
</style>
</head>
<body>
<%
response.setHeader("Cache-control", "no-cache"); // HTTP 1.1
response.setHeader("Cache-control", "no-store");
response.setHeader("Pragma", "no-cache"); // HTTP 1.0
response.setDateHeader("Expire", 0);
%>
<a href="/userone">get all users</a>
<h3>view user</h3>
getMobileInfo
<a href="/indexone">get all mobile details</a>
<form action="/LogoutServlet" method="get">
<input type="submit" value="logout">
</form>
</body>
</html>
这是注销servlet
package login.example;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
@WebServlet(name = "LogoutServlet", urlPatterns = { "/LogoutServlet" })
public class LogoutServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
public LogoutServlet() {
}
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
PrintWriter out = response.getWriter();
response.setContentType("text/html");
HttpSession session = request.getSession();
session.removeAttribute("id");
session.removeAttribute("name");
request.getSession(false);
session.invalidate();
out.println("Thank you,you are successfully logged out");
// response.setHeader("Cache-Control", "no-cache,no-store,must-revalidate");
HttpServletResponse httpResponse = (HttpServletResponse) response;
httpResponse.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); // HTTP 1.1
httpResponse.setHeader("Pragma", "no-cache"); // HTTP 1.0
httpResponse.setDateHeader("Expires", 0); // Proxies.
// request.getRequestDispatcher("login.jsp").include(request, response);
response.sendRedirect("login.jsp");
}
}
我应该添加或删除什么以获得所需的输出,例如在我注销后它不会显示上一页?。。我的代码怎么了?我是否需要依赖或其他任何东西来实现这一点?如何解决这个问题?提前谢谢。。我的url就像http://localhost:8080/home.html
然后http://localhost:8080/login.jsp?
和http://localhost:8080/UserOne?id=1
当你点击后退按钮的网址(/UserOne? id=1
ie:登录。jsp提交方法应该是post
http://www.baeldung.com/swagger-2-documentation-for-spring-rest-api 我将这些依赖项添加到我的项目中: 并将SpringFox Swagger配置为: null 我错过了什么?
我正面临“调用quit()后FirefoxDriver无法使用”的问题。请帮助。 请帮忙
我已经使用IntelliJ版本14.0.2创建了一个jar,但当我试图运行jar时,我会得到一个错误,因为未能从//ABC. jar加载主类清单
我匹配了所有的数据类型,但还是会出错 "不允许从数据类型'INT'到'CHAR'的隐式转换。使用CONVERT函数运行此查询。" 请导游。
当我试图运行dataloader时。py我得到了以下导入错误。我逐行尝试代码,发现在将tensorlayer导入为t1时出现了此错误。 ModuleNotFoundError:没有名为'numpy.core._multiarray_umath'的模块重要错误:numpy.core.multiarray导入失败 上述异常是以下异常的直接原因: Traceback(最近的调用最后):文件”