我制作了两个servlet Authenticate.java和Accept.java
这是Authenticate.java的doGet函数
PreparedStatement stmt = null;
PrintWriter out=response.getWriter();
response.setContentType("text/html");
response.setCharacterEncoding("UTF-8");
try{
int cnt=0;
Class.forName("com.ibm.db2.jcc.DB2Driver");
Connection con= DriverManager.getConnection("jdbc:db2://localhost:50000/SSMS", "kiit", "kiit");
con.setAutoCommit(false);
String s=request.getParameter("userName");
if(s==null){
out.println("You Are Not Authorized");
return;
}
stmt=con.prepareStatement("SELECT COMP_ID,NAME,CONTACT FROM COMPANYREG");
ResultSet rs=stmt.executeQuery();
while(rs.next()){
cnt++;
out.println("<form action='Accept' method='post'> <input type='text' size='20' id='cmpid' value='"+rs.getString(1)+"'><br> Name :"+rs.getString(2)+"<br>Contact: "+rs.getString(3)+"<br><input type='submit' class='confirm' id='"+cnt+"' value='Approve'><br></form>");
}
和Heres Accept.java
String user=request.getParameter("cmpid");
PrintWriter out=response.getWriter();
response.setContentType("text/html");
response.setCharacterEncoding("UTF-8");
out.println("user = "+user);
try{
String cid = null,pss = null,nam = null,add = null,sec = null,cnt = null,ema = null;
Class.forName("com.ibm.db2.jcc.DB2Driver");
Connection con= DriverManager.getConnection("jdbc:db2://localhost:50000/SSMS", "kiit", "kiit");
stmt=con.prepareStatement("SELECT * FROM COMPANYREG WHERE COMP_ID = '"+user+"'");
ResultSet rs=stmt.executeQuery();
out.println("query1");
while(rs.next()){
out.println("query2");
cid = rs.getString(1);
pss=rs.getString(2);
nam=rs.getString(3);
add=rs.getString(4);
sec=rs.getString(5);
cnt=rs.getString(6);
ema=rs.getString(7);
}
out.println("query3");
stmt=con.prepareStatement("INSERT INTO COMPANY VALUES ('"+cid+"','"+pss+"','"+nam+"','"+add+"','"+sec+"',"+cnt+",'"+ema+"')");
int numRowsChanged= stmt.executeUpdate();
if(numRowsChanged==0) out.println("Some Error Encountered Please Re-enter Information values Correctly");
else out.println("You Were Registered Successfully.You will be allowed to login once your details are verified. Thank You");
在Accept.java类中,当我使用request.getParameter(“cmpid”)引用变量“cmpid”时;
它返回null ......有人能告诉我这里究竟出现了什么问题吗?
答案 0 :(得分:1)
out.println("<form action='Accept' method='post'> <input type='text' size='20' id='cmpid' value='"+rs.getString(1)+"'><br> Name :"+rs.getString(2)+"<br>Contact: "+rs.getString(3)+"<br><input type='submit' class='confirm' id='"+cnt+"' value='Approve'><br></form>");
在表单中添加名称属性为“name = cmpid”