关于JSP的一点疑问小结
网络编程 2021-07-05 11:23www.168986.cn编程入门
我在做一个JSP小测试.写的一些代码如下
希望谁能帮我看一看问题出在哪?谢谢!
register.html部分:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>register.html</title>
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
</head>
<body>
<br>
<form action="register.jsp" method = "Post" name = "frm">
用户名:<input type = "text" name = "in_username"><br>
密码:<input type = "password" name = "in_password"><br>
<input type = "submit" name = "submit" value = "提交">
</form>
</body>
</html>
register.jsp部分:
<%@ page language="java" import = java.util. pageEncoding="ISO-8859-1"%>
<%
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 'register.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">
<meta http-equiv = "content-type" content = "text/html;charset = gb2312">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<br>
<%! boolean isnotlogin = false;%>
<%
String username = request.getParameter("username");
String password = request.getParameter("password");
if(username == null || password == null)
{
response.sendRedirect("error.jsp");
return;
}
%>
<jsp:useBean id="person" scope = "page" class = "mypack.register">
<jsp:setProperty name = "person" property = "username" param = "username"/>
<jsp:setProperty name = "person" property = "pwd" param = "password"/>
</jsp:useBean>
<%
isnotlogin = person.judge();
if(!isnotlogin)
{
response.sendRedirect("error.jsp");
return;
}
else
{
session.setAttribute("username", request.getParameter("username"));
%>
<jsp:forward page = "sbmt">
<jsp:param name = "username" value = "<%=username%>"/>
</jsp:forward>
<%
}
%>
</body>
</html>
register.java(JavaBean)部分:
package mypack;
public class register {
private String username = "";
private String pwd = "";
public void setUserName(String nm)
{
this.username = nm;
}
public String getUserName()
{
return this.username;
}
public void setPwd(String pd)
{
this.pwd = pd;
}
public String getPwd()
{
return this.pwd;
}
public boolean judge()
{
boolean temp = false;
if(username.equals("teacher") && pwd.equals("teacher"))
{
temp = true;
}
return temp;
}
}
sbmt.java(Servlet)部分:
package mypack;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
public class sbmt extends HttpServlet {
private static final long serialVersionUID = 1L;
public sbmt() {
super();
}
public void destroy() {
super.destroy();
}
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out
.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
out.println("<HTML>");
out.println(" <HEAD><TITLE>A Servlet</TITLE></HEAD>");
out.println(" <BODY>");
out.print(" This is ");
out.print(this.getClass());
out.println(", using the GET method");
out.println(" </BODY>");
out.println("</HTML>");
out.flush();
out.close();
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
HttpSession session = request.getSession(false);
if(session == null)
{
response.sendRedirect("error.jsp");
return;
}
String usernameone = (String)session.getAttribute("username");
String usernametwo = request.getParameter("username");
if(!usernameone.equals(usernametwo))
{
response.sendRedirect("error.jsp");
return;
}
response.setContentType("text/html;charset = GBK");
request.setAttribute("username", usernametwo);
if(usernametwo.equals("teacher"))
{
response.sendRedirect("teacher.jsp");
return;
}
else
{
response.sendRedirect("error.jsp");
return;
}
}
}
}
register.html部分:
代码如下:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>register.html</title>
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
</head>
<body>
<br>
<form action="register.jsp" method = "Post" name = "frm">
用户名:<input type = "text" name = "in_username"><br>
密码:<input type = "password" name = "in_password"><br>
<input type = "submit" name = "submit" value = "提交">
</form>
</body>
</html>
register.jsp部分:
代码如下:
<%@ page language="java" import = java.util. pageEncoding="ISO-8859-1"%>
<%
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 'register.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">
<meta http-equiv = "content-type" content = "text/html;charset = gb2312">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<br>
<%! boolean isnotlogin = false;%>
<%
String username = request.getParameter("username");
String password = request.getParameter("password");
if(username == null || password == null)
{
response.sendRedirect("error.jsp");
return;
}
%>
<jsp:useBean id="person" scope = "page" class = "mypack.register">
<jsp:setProperty name = "person" property = "username" param = "username"/>
<jsp:setProperty name = "person" property = "pwd" param = "password"/>
</jsp:useBean>
<%
isnotlogin = person.judge();
if(!isnotlogin)
{
response.sendRedirect("error.jsp");
return;
}
else
{
session.setAttribute("username", request.getParameter("username"));
%>
<jsp:forward page = "sbmt">
<jsp:param name = "username" value = "<%=username%>"/>
</jsp:forward>
<%
}
%>
</body>
</html>
register.java(JavaBean)部分:
代码如下:
package mypack;
public class register {
private String username = "";
private String pwd = "";
public void setUserName(String nm)
{
this.username = nm;
}
public String getUserName()
{
return this.username;
}
public void setPwd(String pd)
{
this.pwd = pd;
}
public String getPwd()
{
return this.pwd;
}
public boolean judge()
{
boolean temp = false;
if(username.equals("teacher") && pwd.equals("teacher"))
{
temp = true;
}
return temp;
}
}
sbmt.java(Servlet)部分:
package mypack;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
public class sbmt extends HttpServlet {
private static final long serialVersionUID = 1L;
public sbmt() {
super();
}
public void destroy() {
super.destroy();
}
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out
.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
out.println("<HTML>");
out.println(" <HEAD><TITLE>A Servlet</TITLE></HEAD>");
out.println(" <BODY>");
out.print(" This is ");
out.print(this.getClass());
out.println(", using the GET method");
out.println(" </BODY>");
out.println("</HTML>");
out.flush();
out.close();
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
HttpSession session = request.getSession(false);
if(session == null)
{
response.sendRedirect("error.jsp");
return;
}
String usernameone = (String)session.getAttribute("username");
String usernametwo = request.getParameter("username");
if(!usernameone.equals(usernametwo))
{
response.sendRedirect("error.jsp");
return;
}
response.setContentType("text/html;charset = GBK");
request.setAttribute("username", usernametwo);
if(usernametwo.equals("teacher"))
{
response.sendRedirect("teacher.jsp");
return;
}
else
{
response.sendRedirect("error.jsp");
return;
}
}
}
}
编程语言
- 如何快速学会编程 如何快速学会ug编程
- 免费学编程的app 推荐12个免费学编程的好网站
- 电脑怎么编程:电脑怎么编程网咯游戏菜单图标
- 如何写代码新手教学 如何写代码新手教学手机
- 基础编程入门教程视频 基础编程入门教程视频华
- 编程演示:编程演示浦丰投针过程
- 乐高编程加盟 乐高积木编程加盟
- 跟我学plc编程 plc编程自学入门视频教程
- ug编程成航林总 ug编程实战视频
- 孩子学编程的好处和坏处
- 初学者学编程该从哪里开始 新手学编程从哪里入
- 慢走丝编程 慢走丝编程难学吗
- 国内十强少儿编程机构 中国少儿编程机构十强有
- 成人计算机速成培训班 成人计算机速成培训班办
- 孩子学编程网上课程哪家好 儿童学编程比较好的
- 代码编程教学入门软件 代码编程教程