Advertisement
Guest User

Untitled

a guest
Nov 4th, 2016
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.68 KB | None | 0 0
  1. I am trying to create Simple login page here's my code.Here's my servlet code
  2.  
  3. Servlet
  4. --------------
  5. import java.io.IOException;
  6. import java.io.PrintWriter;
  7. import java.sql.Connection;
  8. import java.sql.DriverManager;
  9. import java.sql.PreparedStatement;
  10. import java.sql.ResultSet;
  11.  
  12. import javax.servlet.ServletException;
  13. import javax.servlet.annotation.WebServlet;
  14. import javax.servlet.http.HttpServlet;
  15. import javax.servlet.http.HttpServletRequest;
  16. import javax.servlet.http.HttpServletResponse;
  17.  
  18. @WebServlet("/MySQLConnect")
  19. public class MySQLConnect extends HttpServlet {
  20. private static final long serialVersionUID = 1L;
  21.  
  22. //do post method calling
  23. protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  24. response.setContentType("text/html");
  25. PrintWriter out = response.getWriter();
  26. String user = request.getParameter("user");
  27. String pass = request.getParameter("pass");
  28. try {
  29. Class.forName("com.mysql.jdbc.Driver");
  30. Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/javademo", "root", "admin");
  31.  
  32. e.printStackTrace();
  33. }
  34. finally{}
  35.  
  36. }
  37. }
  38.  
  39. index.html
  40. ------------------
  41. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  42. <html>
  43. <head>
  44. <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
  45. <title>Insert title here</title>
  46. </head>
  47. <body>
  48. <form method="post" action="MySQLConnect">
  49. UserName :<input type="text" name="user" /><br/><br/>
  50. Password :<input type="password" name="pass" /><br/><br/>
  51. <input type="submit" value="Login" />
  52. </form>
  53. </body>
  54. </html>
  55.  
  56. web.xml
  57. ------------------------
  58. <?xml version="1.0" encoding="UTF-8"?>
  59. <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
  60. <display-name>AuthenticationUsingMySQL</display-name>
  61.  
  62. <servlet>
  63. <servlet-name>MySQLConnect</servlet-name>
  64. <servlet-class>MySQLConnect</servlet-class>
  65. </servlet>
  66. <servlet-mapping>
  67. <servlet-name>MySQLConnect</servlet-name>
  68. <url-pattern>/Login</url-pattern>
  69. </servlet-mapping>
  70. <session-config>
  71. <session-timeout>30</session-timeout>
  72. </session-config>
  73.  
  74. </web-app>
  75.  
  76. i am trying to open page using http://localhost:8080/AuthenticationUsingMySQL/Login but it is showing HTTP Status 405 - HTTP method GET is not supported by this URL.please help
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement