NetBeans Servlet MySQL(NetBeans Servlet MySQL)
这已经解决了
问题在于参数名称。
我正在尝试创建一个基本的登录servlet,它将检查员工的登录详细信息。
但是我的servlet似乎没有与数据库交互,总是将我返回到“tryagain.jsp”。 我究竟做错了什么? 我正在使用glassfish和netbeans。 我也在库文件中有j / connector驱动程序。
这已经解决了
问题在于参数名称。
这是代码。
package loginServlet; import java.io.IOException; import java.io.PrintWriter; import javax.servlet.*; import javax.servlet.http.*; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.sql.*; /** * * @author asus */ public class Login1 extends HttpServlet { public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); Connection conn; PreparedStatement ps; ResultSet rs; String DRIVER = "com.mysql.jdbc.Driver"; String DATABASE_URL = "jdbc:mysql://localhost:3306/northwind"; String uname=request.getParameter("username"); String passwd=request.getParameter("userPass"); try { // load the driver class Class.forName(DRIVER); // establish connection to database conn = DriverManager.getConnection(DATABASE_URL, "jonh86", "ADMIN"); System.out.println("Connected...."); ps = conn.prepareStatement("select * from userdata where user_name = ? and password = ?"); ps.setString(1, uname); ps.setString(2, passwd); rs = ps.executeQuery(); if (rs.next()) { RequestDispatcher rd = request.getRequestDispatcher("WelcomeServlet"); rd.forward(request, response); //out.println(rs.getString(2)); } else { RequestDispatcher rd = request.getRequestDispatcher("tryagain.jsp"); rd.include(request, response); } } catch (Exception e) { System.out.println(e); } } }
THIS HAS BEEN SOLVED
The problem lay with the parameter names.
I am trying to create a basic login servlet that will check the login details of employees.
However my servlet doesn't seem to be interacting with the data base and always returns me to the "tryagain.jsp". What am I doing wrong? I am using glassfish and netbeans. I have j/connector driver in the library files as well.
THIS HAS BEEN SOLVED
The problem lay with the parameter names.
Here is the code.
package loginServlet; import java.io.IOException; import java.io.PrintWriter; import javax.servlet.*; import javax.servlet.http.*; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.sql.*; /** * * @author asus */ public class Login1 extends HttpServlet { public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); Connection conn; PreparedStatement ps; ResultSet rs; String DRIVER = "com.mysql.jdbc.Driver"; String DATABASE_URL = "jdbc:mysql://localhost:3306/northwind"; String uname=request.getParameter("username"); String passwd=request.getParameter("userPass"); try { // load the driver class Class.forName(DRIVER); // establish connection to database conn = DriverManager.getConnection(DATABASE_URL, "jonh86", "ADMIN"); System.out.println("Connected...."); ps = conn.prepareStatement("select * from userdata where user_name = ? and password = ?"); ps.setString(1, uname); ps.setString(2, passwd); rs = ps.executeQuery(); if (rs.next()) { RequestDispatcher rd = request.getRequestDispatcher("WelcomeServlet"); rd.forward(request, response); //out.println(rs.getString(2)); } else { RequestDispatcher rd = request.getRequestDispatcher("tryagain.jsp"); rd.include(request, response); } } catch (Exception e) { System.out.println(e); } } }
原文:https://stackoverflow.com/questions/19172606
最满意答案
你需要加倍每个
%
:%%%%%% this is a comment {resurl, %(resturl)s}
这逃脱了
%
; 输出将每个%%
转换回%
。演示:
>>> val = '''\ ... %%%%%% this is a comment ... ... {resurl, %(resturl)s} ... ''' >>> print val % {"resturl": "http://localhost:500/"} %%% this is a comment {resurl, http://localhost:500/}
You need to double each
%
:%%%%%% this is a comment {resurl, %(resturl)s}
This escapes the
%
; the output transforms each%%
back to%
.Demo:
>>> val = '''\ ... %%%%%% this is a comment ... ... {resurl, %(resturl)s} ... ''' >>> print val % {"resturl": "http://localhost:500/"} %%% this is a comment {resurl, http://localhost:500/}
相关问答
更多-
您可以使用Chromaprint计算一段音乐的指纹。 它应该能够找到类似的音乐文件。 如果你想进一步推动这一点,你可以使用musicbrainz的api来找到关于一段音乐的确切信息。 这些库用于我使用的两个伟大的音乐库标记和排序应用程序: picard和beets 。 You could use Chromaprint, that computes a fingerprint for a piece of music. It should be able to find similar music file ...
-
使用"*/*/*/*/*.gif"斜杠作为DIRECTORY_SEPARATOR常量? $path = FOLDER . '*' . DIRECTORY_SEPARATOR . '*' . DIRECTORY_SEPARATOR . '.gif'; 您可以创建一个类似define('DS', DIRECTORY_SEPARATOR);的快捷方式define('DS', DIRECTORY_SEPARATOR); use "*/*/*/*/*.gif" slashes as DIRECTORY_SEPAR ...
-
Python没有这样的机制。 为每行添加一个#来阻止注释。 有关更多信息,请参阅PEP 8 。 大多数Python IDE支持一种自动为您进行块注释的机制。 例如,在我的机器上的IDLE中,它是Alt + 3和Alt + 4 。 不要使用三联报价 正如您所发现的那样,这是用于文档字符串不阻止注释,尽管它具有类似的效果。 如果你只是暂时评论一下,这是一个临时措施。 Python does not have such a mechanism. Prepend a # to each line to block ...
-
在Python中重命名一个目录中的多个文件[duplicate](Rename multiple files in a directory in Python [duplicate])[2022-08-16]
使用os.rename(src, dst)重命名或移动文件或目录。 $ ls cheese_cheese_type.bar cheese_cheese_type.foo $ python >>> import os >>> for filename in os.listdir("."): ... if filename.startswith("cheese_"): ... os.rename(filename, filename[7:]) ... >>> $ ls cheese_type.ba ... -
:global/{pat}/{cmd}命令将在每个匹配模式的行{cmd}上运行命令{cmd} {pat} 。 您可以通过:normal命令执行tComment命令。 它们一起看起来像这样: :g/@login_required/norm gcc 有关更多帮助请参阅: :h :g :h :norm The :global/{pat}/{cmd} command will run a command, {cmd}, on every line matching pattern, {pat}. You can ...
-
按着这些次序: 选择.pro文件中要注释的行。 按CTRL + / 。 此键盘快捷键可打开/关闭注释。 要么, 手动将#放在行之前。 Follow these steps: Select the line(s) in your .pro file that you want to comment. Press CTRL + /. OR, Manually put # before the line(s).
-
你需要加倍每个% : %%%%%% this is a comment {resurl, %(resturl)s} 这逃脱了% ; 输出将每个%%转换回% 。 演示: >>> val = '''\ ... %%%%%% this is a comment ... ... {resurl, %(resturl)s} ... ''' >>> print val % {"resturl": "http://localhost:500/"} %%% this is a comment {resurl ...
-
这里回答: doc5.DocumentNode.Descendants() .Where(n => n.NodeType == HtmlAgilityPack.HtmlNodeType.Comment) .ToList() .ForEach(n => n.Remove()); 注意:ToList是必需的,因为您无法更改要枚举的序列。 Thank you all for your help. I found solution in following function. Just c ...
-
hg help的输出非常全面。 还有hg书: http : //hgbook.red-bean.com/ 在您的情况下,您需要输出hg manifest ,其中列出了属于某个修订版的所有文件。 可以在那里找到用于检查不需要的文件的新变更集的小型提交挂钩: https : //hg.openttdcoop.org/misc/files/tip/mercurial/hooks/check_commit.py请注意,只要您使用内部API在该示例中,您的脚本被认为是来自mercurial的派生作品,并且也需要使用其 ...
-
哈希/#不是评论[重复](Hash/# not a comment [duplicate])[2022-11-14]
Python不会将以下文本视为注释。 您的IDE可能会错误地将其解释为并错误地应用语法突出显示,但引用字符串中的#只是# ,而不是注释的开头。 Python is not treating the following text as a comment. Your IDE might be mistakenly interpreting it as such and applying syntax highlighting incorrectly, but a # inside a quoted strin ...