Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- I am trying to create Simple login page here's my code.Here's my servlet code
- Servlet
- --------------
- import java.io.IOException;
- import java.io.PrintWriter;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import javax.servlet.ServletException;
- import javax.servlet.annotation.WebServlet;
- import javax.servlet.http.HttpServlet;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- @WebServlet("/MySQLConnect")
- public class MySQLConnect extends HttpServlet {
- private static final long serialVersionUID = 1L;
- //do post method calling
- protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
- response.setContentType("text/html");
- PrintWriter out = response.getWriter();
- String user = request.getParameter("user");
- String pass = request.getParameter("pass");
- try {
- Class.forName("com.mysql.jdbc.Driver");
- Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/javademo", "root", "admin");
- e.printStackTrace();
- }
- finally{}
- }
- }
- index.html
- ------------------
- <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
- <title>Insert title here</title>
- </head>
- <body>
- <form method="post" action="MySQLConnect">
- UserName :<input type="text" name="user" /><br/><br/>
- Password :<input type="password" name="pass" /><br/><br/>
- <input type="submit" value="Login" />
- </form>
- </body>
- </html>
- web.xml
- ------------------------
- <?xml version="1.0" encoding="UTF-8"?>
- <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">
- <display-name>AuthenticationUsingMySQL</display-name>
- <servlet>
- <servlet-name>MySQLConnect</servlet-name>
- <servlet-class>MySQLConnect</servlet-class>
- </servlet>
- <servlet-mapping>
- <servlet-name>MySQLConnect</servlet-name>
- <url-pattern>/Login</url-pattern>
- </servlet-mapping>
- <session-config>
- <session-timeout>30</session-timeout>
- </session-config>
- </web-app>
- 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