I have below web application. Objective is to give success or failure message after database connection. In this application i am having one Login.jsp and loginHelper.java
Please help me. i need this help.
I hava a Login.JSP with below code.
-----------------------------------
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ page language="java"%>
<%@ page import="java.sql.*"%>
<%@ page import="com.test.loginHelper"%>
<%@ page import="java.util.*"%>
<%@ page import="java.text.*"%>
<%@ page import="javax.servlet.http.*"%>
<%
String user = request.getParameter("uname");
String pass = request.getParameter("pwd");
int stat;
//String dbURL = "jdbc:http://sqlserverlocalhost:1433;databaseName=acc";
loginHelper tc = new loginHelper();
stat=tc.checkLogin(user,pass);
if (stat!= -1) {
%>
{"status":"success"}
<% }else{
%>
{"status":"failed"}
<%} %>
And i have one one Helper class with name loginHelper.java
package com.test;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
//import com.sun.org.apache.xalan.internal.utils.ObjectFactory;
public class loginHelper {
public int checkLogin(String uname,String pass) {
int status=-1;
Connection conn = null;
String dbName = "Test";
String serverip="localhost";
String serverport="1433";
String url = "jdbc:sqlserver://"+serverip+":"+serverport+";databaseName="+dbName+"";
String driver = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
String databaseUserName = uname;
String databasePassword = pass;
try {
Class.forName(driver).newInstance();
} catch (InstantiationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
conn = DriverManager.getConnection(url, databaseUserName, databasePassword);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if (conn!=null) {
status=1;
}
else
{
status=-1;
}
return status;
}
}
When i run this in eclipse with tomcat 7 server configuration. in tomcat i get 505 error message please help me out.
Aucun commentaire:
Enregistrer un commentaire