我写了这两个文件: 寄存器。 html(用于注册它们的用户)和register.jsp(用于后端活动) 当用户注册时,他被重定向到服务器页面,但重定向后页面是空白显示没有.. 下面是两个文件的代码:
`的寄存器(HTML)
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<form action="http://localhost:9090/RegTrial/sel.jsp">
Rec: <input type="text" name="rec">
<br>
Comp: <input type="text" name="comp">
<br>
<input type="submit" value="submit" name="submit">
<input type="reset" value="clear">
</form>
</body>
Register.jsp
<html>
<%@page import="java.sql.*" language="java"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<%
String rec_no=request.getParameter("rec");
String comp_no=request.getParameter("comp");
Connection con1;
Statement stmt1=null;
ResultSet rs;
String recDb=null,compDb=null;
try
{
out.println("Rec:"+rec_no);
out.println("Comp:"+comp_no);
out.println("*****************************");
Class.forName("com.mysql.jdbc.Driver");
String url="jdbc:mysql://localhost:3306/register";
String user="root";
String password="department";
con1=DriverManager.getConnection(url,user,password);
stmt1=con1.createStatement();
String query="select receipt_no,comp_no from receipt where receipt_no = '"+rec_no+"' and comp_no = '"+comp_no+"'; ";
rs=stmt1.executeQuery("query");
if(rs.next())
{
recDb=rs.getString(1);
compDb=rs.getString(2);
out.println("Rec:"+rec_no);
out.println("RecD:"+recDb);
out.println("Comp:"+comp_no);
out.println("CompD:"+compDb);
if( rec_no.equalsIgnoreCase(recDb) && comp_no.equalsIgnoreCase(compDb))
{
out.println("already registered");
}
else
{
response.sendRedirect("www.google.com");
}
}
}
catch(Exception e)
{
e.printStackTrace();
}
%>
</body>
</html>
我设置了环境变量: CATALINA_HOME:D:\ apache-tomcat-7.0.65
classpath:。; D:\ apache-tomcat-7.0.65 \ lib \ servlet-api.jar; D:\ apache-tomcat-7.0.65 \ jar \ mysql-connector-java-5.1.37-bin的.jar;
路径:C:\ Program Files(x86)\ Java \ jdk1.7.0_40 \ bin; C:\ Program Files \ MySQL \ MySQL Server 5.5 \ bin
JAVA_HOME:C:\ Program Files(x86)\ Java \ jdk1.7.0_40
(使用netbeans 7.3,mwsql 5.5,apache tomcat 7.0)