我在java文件中有一些html代码。在'textarea'元素下的'lower div'中有一个提交类型按钮。
我想知道如何识别此按钮是否已被点击?我已经阅读了一些答案,但没有受到它的好处。他们中的大多数人都说这样尝试String name = request.getParameter("Parameter_name")
如果name变量为null,则不会单击它,否则单击。
我使用了这种技术,发现名称变量总是在我点击按钮后返回null。这是我的代码
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.sql.*;
public class ProfileServlet extends HttpServlet{
public void doPost(HttpServletRequest req,HttpServletResponse res){
try{
res.setContentType("text/html");
PrintWriter pw = res.getWriter();
pw.print("Under Construction");
String fullname="",gender="",email="";
//Database connection
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/virtualcard","root","");
PreparedStatement pst = con.prepareStatement("SELECT * FROM info WHERE name=?");
String name = req.getParameter("username");//getting username from external html form
pst.setString(1,name);
ResultSet rs = pst.executeQuery();
byte[] bytes = new byte[1024 * 1024 * 10];
while(rs.next()){
fullname = rs.getString(1);
gender = rs.getString(4);
email = rs.getString(5);
Blob b = rs.getBlob(6);
bytes= b.getBytes(1,(int)b.length());//here 1 represents first image
}
//internal html
pw.print("<!DOCTYPE html>"+
"<html>\n"+
"<head>\n"+
"<title>Test Web</title>\n"+
"<link rel=\"stylesheet\" type=\"text/css\" href=\"../vcard/profile.css\">\n"+
"</head>\n"+
"<body>\n"+
"<div class=\"main\">\n"+
"<div class=\"upper\">\n"+
"<div class=\"image\">\n"+
"<img src=\"\"style=\"width: 200px;height: 200px;border: 2px solid #D7EDC5\" />\n"+
"</div>\n"+//image div ends here
"<div class=\"bar\"></div>\n"+
"<div class=\"info\">\n"+
"Name :"+" "+fullname+"<br><br>"+
"Email :"+" "+email+"<br><br>"+
"Gender :"+" "+gender+"<br>"+
"</div>\n"+//info div ends here
"<div class=\"navigation\">\n"+
"<a href=\"\">Account</a>\n"+
"<a href=\"\">Logout</a>\n"+
"</div>\n"+
"</div>\n"+//div upper ends here
"<hr>\n"+
"<div class=\"lower\">\n"+
"<div class=\"status\">\n"+
"<textarea rows=\"10\" cols=\"60\" name=\"status2\" style=\"font-family: Impact\">\n"+
"Hello There..."+
"</textarea>\n"+
"<input type=\"submit\" name=\"post\" value=\"Post\" />\n"+
"</div>\n"+
"</div>\n"+
"</div>\n"+
"</body>\n"+
"</html>");
}catch(Exception ex){
ex.printStackTrace();
}
}
}