MVC结构解释了全部服务n [英] MVC Structure explained with full Services n all

查看:74
本文介绍了MVC结构解释了全部服务n的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

连接



/ *

*要更改此模板,请选择工具|模板

*并在编辑器中打开模板。

* /

package com.ignite.Ignite114_Career.utils;



import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.SQLException;



/ **

*

* @author ignite114

* /

公共类ConnectionManager {

私人连接;



/ **

*

* @throws ClassNotFoundException

* @throws SQLException

* /

public ConnectionManager()抛出ClassNotFoundException,SQLException {

String dbURL,user,pwd;

dbURL =jdbc:mysql:// localhost:3306 / ignite114_careercorner;

user = root;

pwd =root;

Class.forName(com.mysql.jdbc.Driver);

this .connection = DriverManager.getConnection(dbU RL,user,pwd);

}



公共连接getConnection(){

返回this.connection ;

}



}

// ergistration servlet



/ *

*要更改此模板,请选择工具|模板

*并在编辑器中打开模板。

* /

package com.ignite.Ignite114_Career.servlets;



import com.ignite.Ignite114_Career.beans.RegistrationBeans;

import com.ignite.Ignite114_Career.managers.RegistrationManagers;

import java.io.IOException;

import java.io.PrintWriter;

import java.sql.SQLException;

import java.util.logging .Level;

import java.util.logging.Logger;

import javax.servlet.ServletException;

import javax.servlet.annotation。 WebServlet;

import javax.servlet.http.HttpServlet;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http .HttpServletResponse;



/ **

*

* @author ignite114

* /

@WebServlet(name =Registration,urlPatterns = {/ Registration})

公共类注册扩展HttpServlet {



布尔结果;

布尔值resultlogin;



@Override

protected void doPost(HttpServletRequest request,HttpServletResponse response)

抛出ServletException,IOException {

PrintWriter out = response.getWriter();

String s_name = null,s_email = null,s_pass = null,ports = null,s_course = null,s_city = null,s_mobile = null,s_percentage = null;

字符串ep_name = null,e_email = null, e_pass = null,e_comp = null,e_office = null,e_mob = null,e_cpname = null,e_number = null;

字符串a_name = null,a_email = null,a_pass = null,a_comp = null,a_mob = null,a_batch = null,a_salary = null;

String email123 = null,password123 = null;

// String申请人;



//申请人=<%= request.getAttribute(申请人)。toString()%> ;;

//申请人<%= request.getAttribute(申请人)%> .toString();





String申请人= null;



申请人= request.getParameter(申请人)。toString();







if(Applicant.equalsIgnoreCase((Student))){



s_name = request.getParameter( stu_name)。toString(); // name

s_email = request.getParameter(stu_email)。toString(); // email

s_pass = request.getParameter (stu_pass)。toString(); //密码

umbersatch = request.getParameter(stu_batch)。toString(); //批处理

s_course = request .getParameter(stu_course)。toString(); // course

s_city = request.getParameter(stu_city)。toString(); // city

s_mobile = request.getParameter(stu_mob)。toString(); //手机号码

s_percentage = request.getPar ameter(stu_per)。toString(); //百分比

out.print(名字是:+ s_name +,posotion是:+ s_email + s_pass + pumpatch + s_course + s_city + s_mobile + s_percentage);

out.print(申请人价值是+申请人);

}





if(Applicant.equalsIgnoreCase((Alumni))){

a_name = request.getParameter(alm_name)。toString() ; //名称

a_email = request.getParameter(alm_email)。toString(); // email

a_pass = request.getParameter(alm_pass)。toString (); //密码

a_comp = request.getParameter(alm_comp)。toString(); //公司名称

a_batch = request.getParameter(alm_batch ).toString(); //办公地点

a_mob = request.getParameter(alm_mob)。toString(); // mobile numer

a_salary = request.getParameter ( alm_salary)。的toString() ; //联系人



// out.print(名字是:+ ep_name +,posotion是:+ e_email + e_pass +

// e_office + e_mob + e_cpname);



}

//

// / ** ////////////////////////////

//

如果( Applicant.equalsIgnoreCase((Employer))){

ep_name = request.getParameter(emp_name)。toString();

e_email = request.getParameter( emp_email)。toString();

e_pass = request.getParameter(emp_pass)。toString();

// e_comp = request.getParameter(emp_comp ).toString();

e_office = request.getParameter(emp_office)。toString();

e_mob = request.getParameter(emp_mob)。toString( );

e_cpname = request.getParameter(emp_cpname)。toString();

// out.print(你的名字是:+ ep_name +和p osotion是:+ e_email + e_pass +

// e_comp + e_office + e_mob + e_cpname);



}



if(s_email!= null&& s_pass!= null)

{

email123 = request.getParameter(stu_email)。toString(); // email

password123 = request.getParameter(stu_pass)。toString(); // password

}

else if(e_email!= null&& e_pass!= null)

{



email123 = request.getParameter(emp_email)。toString();

password123 = request .getParameter(emp_pass)。toString();

}

else if(a_email!= null&& a_pass!= null)

{

email123 = request.getParameter(alm_email)。toString(); // email

password123 = a_pass = request.getParameter(alm_pass) .toString(); //密码

}





RegistrationBeans rb = new RegistrationBeans();

rb.setApplicant(申请人);

rb.setA_batch(a_batch);

rb.setA_comp(a_comp);

rb.setA_email(a_email);

rb.setA_name(a_name);

rb.setA_mob(a_mob);

rb.setA_pass(a_pass);

rb.setA_salary(a_salary);







// rb.setE_comp(e_comp);

rb.setE_cpname(e_cpname);

rb.setE_email(e_email);

rb.setE_pass(e_pass);

// rb.setE_number(e_number);

rb.setE_mob(e_mob);

rb.setEp_name(ep_name);

rb.setE_office(e_office);







//完美

rb.setS_batch(saveatch);

rb.setS_course(s_course );

rb.setS_percentage(s_percentage);

rb.setS_name(s_name);

rb.setS_email(s_email);

rb.setS_city(s_city);

rb.setS_pass(s​​_p屁股);

rb.setS_mobile(s_mobile);



//设置登录变量



rb.setEmail123(email123);

rb.setPassword123(password123);



///插入注册详情

尝试{

result = new RegistrationManagers()。insertuser(rb);



} catch(ClassNotFoundException ex) ){

Logger.getLogger(RegistrationManagers.class.getName())。log(Level.SEVERE,null,ex);

}



if(result = true)

{

// String names =;

//尝试{

// // names = new FeedbackManagers()。getDataFromDataBase();

//} catch(ClassNotFoundException ex){

// // Logger.getLogger(FeedbackServlet.class.getName())。log(Level.SEVERE,null,ex);

//} catch( SQLException ex){

// // Logger.getLogger(FeedbackServlet.class.getName())。log(Level.SEVERE,null,ex);

// }

response.setContentType(text / html);

// request.setAttribute(name,names);

/ /

request.getRequestDispatcher(Login.jsp)。forward(request,response);

}

else

{

//系统。提醒(不是用户......现在注册);

response.sendRedirect(Registration.jsp);

}

$ / b $ b $ / b
尝试{

resultlogin = new RegistrationManagers()。insertlogindetails(rb);



}

catch(ClassNotFoundException ex){

Logger.getLogger(RegistrationManagers.class.getName())。log (Level.SEVERE,null,ex);

}

if(resultlogin = true)

{



response.setContentType(text / html);

// request.setAttribute(name,names);

//

request.getRequestDispatcher(Login.jsp)。forward(request,response);

}

else

{

//系统。提醒(不是用户......现在注册);

response.sendRedirect(Registration.jsp);

}

}

}

//





注册管理




/ *

*要更改此模板,请选择工具|模板

*并在编辑器中打开模板。

* /

package com.ignite.Ignite114_Career.managers;







import com.ignite.Ignite114_Career.beans.RegistrationBeans;

import com.ignite .Ignite114_Career.dao.RegistrationDAO;

import java.sql.SQLException;



/ **

*

* @author ignite114

* /

公共类注册管理员{







public boolean insertuser(RegistrationBeans rb)抛出ClassNotFoundException

{

返回新的RegistrationDAO()。insertuser( rb);

}

公共布尔值insertlogindetails(RegistrationBeans rb)抛出ClassNotFoundException

{

返回新的RegistrationDAO( ).insertlogindetails(rb);

}



public String getDataFromDataBase()throws ClassNotFoundException,SQLException

{

返回新的RegistrationDAO()。getDataFromDataBase();

}

public boolean updateuser (RegistrationBeans rb)抛出ClassNotFoundException

{



返回新的RegistrationDAO()。updateuser(rb);

}



}

// rei dao

/ *

*至更改此模板,选择工具|模板

*并在编辑器中打开模板。

* /

package com.ignite.Ignite114_Career.dao;





import com.ignite.Ignite114_Career.beans.RegistrationBeans;

import com.ignite.Ignite114_Career.utils.ConnectionManager;

import java.sql.Connection;

import java.sql.PreparedStatement;

import java.sql.ResultSet;

import java.sql.SQLException;



/ **

*

* @author ignite114 < br $>
* /

公共类RegistrationDAO {



private String finalString;

< br $>


public boolean updateuser(RegistrationBeans rb)throws ClassNotFoundException {

boolean saved = false;

Connection con = null ;

PreparedStatement ps = null;



尝试{





con = new ConnectionManager()。getConnection();



if(rb.getApplicant()。equalsIgnoreCase(Student)){

ps = con.prepareStatement(更新学生在哪里(姓名=?,电子邮件=?,密码=?,Mobile_no = ?,批次=?,课程=?,城市=?,百分比=?) ;);

ps.setString(1,rb.getS_name());

ps.setString(2,rb.getS_email());

ps.setString(3,rb.getS_pass());

// ps.setString(4,rb.getS_Course));

// ps .setString(4,rb.getS_course));

ps.setString(4,rb.getS_mobile());

ps.setString(5,rb.getS_batch( ));

ps.setString(6,rb.getS_course());



ps.setString(7,rb.getS_city( ));

// ps.setString(6,rb.getS_Per()));

ps.setString(8,rb.getS_percentage());









ps.executeUpdate();



saved = true;

}

}



catch(Exception ex){

ex.printStackTrace();

saved = false;

}终于{

试试{

if(ps!= null){

ps.close();

}

if(con!= null){

con.close();

}

} catch(SQLException ex){

ex.printStackTrace( );

}

}



返回已保存;



}

//插入使用

public boolean insertuser(RegistrationBeans rb)抛出ClassNotFoundExcep {$ $
布尔保存=假;

连接con = null;

PreparedStatement ps = null;



尝试{





con = new ConnectionManager()。getConnection();



if(rb.getApplicant()。equalsIgnoreCase(Student)){

ps = con.prepareStatement(插入学生(姓名,电子邮件,密码) ,Mobile_no,Batch,Course,City,Percentage)值(?,?,?,?,?,?,?,?););

ps.setString(1,rb.getS_name ());

ps.setString(2,rb.getS_email());

ps.setString(3,rb.getS_pass());

// ps.setString(4,rb.getS_Course));

// ps.setString(4,rb.getS_course));

ps。 setString(4,rb.getS_mobile());

ps.setString(5,rb.getS_batch());

ps.setString(6,r b.getS_course());



ps.setString(7,rb.getS_city());

// ps.setString( 6,rb.getS_Per()));

ps.setString(8,rb.getS_percentage());









ps.executeUpdate();



saved = true;

}





else if(rb.getApplicant()。equalsIgnoreCase(Employer)){







ps = con.prepareStatement(插入雇主(Company_Name,Email,Password,Representative_Name,HeadOffice_Location, Contact_number)值(?,?,?,?,?,?););

ps.setString(1,rb.getEp_name());

ps .setString(2,rb.getE_email()); // email

ps.setString(3,rb.getE_pass()); //传递

ps.setString(4,rb.getE_cpname()); //代表名称

ps.setString(5,rb.getE_office()); // location

ps.setString(6,rb.getE_mob()); //数字



ps.executeUpdate();



saved = true;

}





else if(rb.getApplicant()。equalsIgnoreCase(Alumni)){







ps = con.prepareStatement(插入校友(姓名,电子邮件,密码,Mobile_No,批量,薪水, Company_Placed)值(?,?,?,?,?,?,?););

ps.setString(1,rb.getA_name()); // name;

ps.setString(2,rb.getA_email()); //电子邮件

ps.setString(3,rb.getA_pass()); //传递

ps.setString(4,rb.getA_mob()); // mobile

ps.setString(5,rb.getA_batch()); //批处理

ps.setString(6,rb.getA_salary()); //工资

ps.setString(7,rb.getA_comp()); // comp comp





ps.executeUpdate();



saved = true;

}











} catch(Exception ex){

ex。 printStackTrace();

saved = false;

}最后{

尝试{

if(ps!= null){

ps.close();

}

if(con!= null){

con.close();

}

} catch(SQLException ex){

ex.printS tackTrace();

}

}



返回已保存;

}

//插入登录







public boolean insertlogindetails(RegistrationBeans rb抛出ClassNotFoundException {

boolean saved = false;

Connection con = null;

PreparedStatement ps = null;

尝试{





con = new ConnectionManager()。getConnection();





ps = con.prepareStatement(插入登录(电子邮件,密码,用户类型)值(?,?,?););

ps .setString(1,rb.getEmail123());

ps.setString(2,rb.getPassword123());

ps.setString(3,rb.getApplicant ());



ps.executeUpdate();



saved = true;

} catch(exception ex){

ex.printStackTrace();

已保存= false;

}最后{

尝试{

if(ps!= null){

ps。 close();

}

if(con!= null){

con.close();

}

} catch(SQLException ex){

ex.printStackTrace();

}

}



返回保存;

}





public String getDataFromDataBase()抛出ClassNotFoundException,ClassNotFoundException,ClassNotFoundException,SQLException {

Connection con = null;

String finalString =;

PreparedStatement ps = null;

con = new ConnectionManager()。getConnection();

ps = con.prepareStatement(从`feedback`中选择名字);



ResultSet re = ps.executeQuery();



while(re.next())

{

finalString = finalString + re.getString(name)+,;

}

返回finalString;

}



}

bean



//

/ *

*要更改此模板,请选择工具|模板

*并在编辑器中打开模板。

* /

package com.ignite.Ignite114_Career.beans;



/ **

*

* @author ignite114

* /

公共类RegistrationBeans {



字符串s_name,s_email,s_pass,saveatch,s_course,s_city,s_mobile,s_percentage;



字符串ep_name,e_email,e_pass,e_comp,e_office,e_mob,e_cpname,e_number;

字符串a_name,a_email,a_pass,a_comp,a_mob,a_batch,a_salary;

private String申请人;



private String email123;



private String password123;





public String getS_name(){

return s_name;

}



public void setS_name(String s_name){

this.s_name = s_name;

}


public String getS_email(){

return s_email;

}



public void setS_email(String s_email){

this.s_email = s_email;

}



public String getS_pass( ){

返回s_pass;

}



public void setS_pass(String s_pass){

this.s_pass = s_pass;

}



public String getS_batch(){

return saveatch;

}



public void setS_batch(StringWareatch){

this.s_batch = saveatch; < br $>
}



public String getS_course(){

返回s_course;

}



public void setS_course(String s_course){

this.s_course = s_course;

}



public String getS_city(){

返回s_city;

}



public void setS_city(String s_city){

this.s_city = s_city;

}



public String getS_mobile(){

返回s_mobile;

}



public void setS_mobile(String s_mobile){

this.s_mobile = s_mobile;

}



public String getS_percentage(){

返回s_percentage;

}



public void setS_percentage(String s_percentage){

this.s_percentage = s_percentage;

}



public String getEp_name(){

return ep_name;

}



public void setEp_name(String ep_name){

this.ep_name = ep_name;

}



public String getE_email(){

返回e_email;

}



public void setE_email(String e_email){

this.e_email = e_email;

}



public String getE_pass(){

return e_pass;

}



public void setE_pass(String e_pass){

this.e_pass = e_pass;

}



public String getE_comp(){

return e_comp;

}



// public void setE_comp(String e_comp){

// this.e_comp = e_comp;

//}



public String getE_office(){

return e_office;

}



public void setE_office(String e_office){

this.e_office = e_office;

}



public String getE_mob(){

返回e_mob;

}



public void setE_mob (String e_mob){

this.e_mob = e_mob;

}



public String getE_cpname(){

返回e_cpname;

}



public void setE_cpname(String e_cpname){

this.e_cpname = e_cpname;

}



// public String getE_number(){

/ / return e_number;

//}



public void setE_number(String e_number){

this.e_number = e_number;

}



public String getA_name(){

return a_name;

}



public void setA_name(String a_name){

this.a_name = a_name;

}



public String getA_email(){

返回a_email;

}



public void setA_email(String a_email){

this.a_email = a_email;

}



public String getA_pass(){

返回a_pass;

}



public void setA_pass(String a_pass){

this.a_pass = a_pass;

}



public String getA_comp(){

返回a_comp;

}



public void setA_comp(String a_comp){

this.a_comp = a_comp;

}



public String getA_mob(){

返回a_mob;

}



public void setA_mob(String a_mob){

this.a_mob = a_mob;

}



public String getA_batch() {

返回a_batch;

}



public void setA_batch(String a_batch){

this.a_batch = a_batch;

}



public String getA_salar y(){

返回a_salary;

}



public void setA_salary(String a_salary){

this.a_salary = a_salary;

}



public String getApplicant(){

返回申请人;

}



public void setApplicant(String申请人){

this.Applicant =申请人;

}



public String getEmail123(){

return email123;

}



public void setEmail123(String email123){

this.email123 = email123;

} < br $>


public String getPassword123(){

返回密码123;

}



public void setPassword123(String password123){

this.password123 = password123;

}





}

// gin dao

公共类LoginDAO {



public String login(LoginBeans lb)抛出ClassNotFoundException,ClassNotFoundException,ClassNotFoundException,SQLException {

连接con = null;

String finalString =;

PreparedStatement ps = null;

con = new ConnectionManager ()。getConnection();

ps = con.prepareStatement(从`login`中选择usertype,其中email =?和密码=?);

ps.setString(1,lb.getEmail());

ps.setString(2,lb.getPassword());

ResultSet re = ps.executeQuery();

// String name =;

// String type =;

// String res =;

while(re.next())

{

finalString = finalString + re.getString(usertype);

System.out.println(用户类型是+ finalString);

}

return finalString;

}



// logout

公共类LogoutServlet扩展HttpServlet {





@Override

protected void doGet(HttpServletRequest请求,HttpServletResponse响应)

抛出ServletException, IOException {





HttpSession会话;

sessi on = request.getSession(false);

String type = (String) session.getAttribute(\"usertype\");

session.invalidate();

if (type.equalsIgnoreCase(\"Student\")) {

response.sendRedirect(\"student.jsp\");

}



if (type.equalsIgnoreCase(\"Alumni\")) {

response.sendRedirect(\"Alumni.jsp\");

}

if (type.equalsIgnoreCase(\"Employer\")) {

response.sendRedirect(\"Employer.jsp\");

}

}





}

//

<%

String authenticUser;

session = request.getSession(false);



if(null == session.getAttribute(\"email\"))

{

response.sendRedirect(\"index.jsp\");

}

else

{

authenticUser = session.getAttribute(\"email\").toString();

// out.print(\"The Session Value is\"+authenticUser);

session.setAttribute(\"useremail\",authenticUser);

}



%>

connection

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.ignite.Ignite114_Career.utils;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

/**
*
* @author ignite114
*/
public class ConnectionManager {
private Connection connection;

/**
*
* @throws ClassNotFoundException
* @throws SQLException
*/
public ConnectionManager() throws ClassNotFoundException, SQLException{
String dbURL, user, pwd;
dbURL="jdbc:mysql://localhost:3306/ignite114_careercorner";
user="root";
pwd="root";
Class.forName("com.mysql.jdbc.Driver");
this.connection = DriverManager.getConnection(dbURL, user, pwd);
}

public Connection getConnection(){
return this.connection;
}

}
//ergistration servlet

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.ignite.Ignite114_Career.servlets;

import com.ignite.Ignite114_Career.beans.RegistrationBeans;
import com.ignite.Ignite114_Career.managers.RegistrationManagers;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
*
* @author ignite114
*/
@WebServlet(name = "Registration", urlPatterns = {"/Registration"})
public class Registration extends HttpServlet {

boolean result;
boolean resultlogin;

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
PrintWriter out = response.getWriter();
String s_name = null, s_email = null, s_pass = null, s_batch = null, s_course = null, s_city = null, s_mobile = null, s_percentage = null;
String ep_name = null, e_email = null, e_pass = null, e_comp = null, e_office = null, e_mob = null, e_cpname = null, e_number = null;
String a_name = null, a_email = null, a_pass = null, a_comp = null, a_mob = null, a_batch = null, a_salary = null;
String email123 = null, password123 = null;
//String Applicant;

// Applicant= <%=request.getAttribute("Applicant").toString() %>;
// Applicant <%= request.getAttribute("Applicant") %>.toString();


String Applicant = null;

Applicant = request.getParameter("Applicant").toString();



if (Applicant.equalsIgnoreCase(("Student"))) {

s_name = request.getParameter("stu_name").toString();//name
s_email = request.getParameter("stu_email").toString();//email
s_pass = request.getParameter("stu_pass").toString();//password
s_batch = request.getParameter("stu_batch").toString();//batch
s_course = request.getParameter("stu_course").toString();//course
s_city = request.getParameter("stu_city").toString();//city
s_mobile = request.getParameter("stu_mob").toString();//mobile number
s_percentage = request.getParameter("stu_per").toString();//percentage
out.print("Hi the name is: " + s_name + "and the posotion is: " + s_email + s_pass + s_batch + s_course + s_city + s_mobile + s_percentage);
out.print("the applicant values is" + Applicant);
}


if (Applicant.equalsIgnoreCase(("Alumni"))) {
a_name = request.getParameter("alm_name").toString();//name
a_email = request.getParameter("alm_email").toString();//email
a_pass = request.getParameter("alm_pass").toString();//password
a_comp = request.getParameter("alm_comp").toString();//company name
a_batch = request.getParameter("alm_batch").toString();//office location
a_mob = request.getParameter("alm_mob").toString();//mobile numer
a_salary = request.getParameter("alm_salary").toString();//contact person

// out.print("Hi the name is: "+ ep_name+ "and the posotion is: "+e_email+e_pass+
// e_office+ e_mob+ e_cpname);

}
//
// /**////////////////////////////
//
if (Applicant.equalsIgnoreCase(("Employer"))) {
ep_name = request.getParameter("emp_name").toString();
e_email = request.getParameter("emp_email").toString();
e_pass = request.getParameter("emp_pass").toString();
// e_comp=request.getParameter("emp_comp").toString();
e_office = request.getParameter("emp_office").toString();
e_mob = request.getParameter("emp_mob").toString();
e_cpname = request.getParameter("emp_cpname").toString();
// out.print("Hi the name is: "+ ep_name+ "and the posotion is: "+e_email+e_pass+
// e_comp+ e_office+ e_mob+ e_cpname);

}

if(s_email!=null && s_pass!=null )
{
email123=request.getParameter("stu_email").toString();//email
password123=request.getParameter("stu_pass").toString();//password
}
else if(e_email!=null && e_pass!=null )
{

email123=request.getParameter("emp_email").toString();
password123=request.getParameter("emp_pass").toString();
}
else if(a_email!=null && a_pass!=null )
{
email123=request.getParameter("alm_email").toString();//email
password123=a_pass = request.getParameter("alm_pass").toString();//password
}


RegistrationBeans rb = new RegistrationBeans();
rb.setApplicant(Applicant);
rb.setA_batch(a_batch);
rb.setA_comp(a_comp);
rb.setA_email(a_email);
rb.setA_name(a_name);
rb.setA_mob(a_mob);
rb.setA_pass(a_pass);
rb.setA_salary(a_salary);



// rb.setE_comp(e_comp);
rb.setE_cpname(e_cpname);
rb.setE_email(e_email);
rb.setE_pass(e_pass);
// rb.setE_number(e_number);
rb.setE_mob(e_mob);
rb.setEp_name(ep_name);
rb.setE_office(e_office);



//perfect
rb.setS_batch(s_batch);
rb.setS_course(s_course);
rb.setS_percentage(s_percentage);
rb.setS_name(s_name);
rb.setS_email(s_email);
rb.setS_city(s_city);
rb.setS_pass(s_pass);
rb.setS_mobile(s_mobile);

// set login variables

rb.setEmail123(email123);
rb.setPassword123(password123);

/// insert registration details
try {
result = new RegistrationManagers().insertuser(rb);

} catch (ClassNotFoundException ex) {
Logger.getLogger(RegistrationManagers.class.getName()).log(Level.SEVERE, null, ex);
}

if (result = true)
{
// String names = "";
// try {
// // names = new FeedbackManagers().getDataFromDataBase();
// } catch (ClassNotFoundException ex) {
// // Logger.getLogger(FeedbackServlet.class.getName()).log(Level.SEVERE, null, ex);
// } catch (SQLException ex) {
// // Logger.getLogger(FeedbackServlet.class.getName()).log(Level.SEVERE, null, ex);
// }
response.setContentType("text/html");
// request.setAttribute("name", names);
//
request.getRequestDispatcher("Login.jsp").forward(request, response);
}
else
{
//System. Alert("Not a User.... Register Now");
response.sendRedirect("Registration.jsp");
}



try {
resultlogin = new RegistrationManagers().insertlogindetails(rb);

}
catch (ClassNotFoundException ex) {
Logger.getLogger(RegistrationManagers.class.getName()).log(Level.SEVERE, null, ex);
}
if (resultlogin = true)
{

response.setContentType("text/html");
// request.setAttribute("name", names);
//
request.getRequestDispatcher("Login.jsp").forward(request, response);
}
else
{
//System. Alert("Not a User.... Register Now");
response.sendRedirect("Registration.jsp");
}
}
}
//


Registration manage


/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.ignite.Ignite114_Career.managers;



import com.ignite.Ignite114_Career.beans.RegistrationBeans;
import com.ignite.Ignite114_Career.dao.RegistrationDAO;
import java.sql.SQLException;

/**
*
* @author ignite114
*/
public class RegistrationManagers {



public boolean insertuser(RegistrationBeans rb) throws ClassNotFoundException
{
return new RegistrationDAO().insertuser(rb);
}
public boolean insertlogindetails(RegistrationBeans rb) throws ClassNotFoundException
{
return new RegistrationDAO().insertlogindetails(rb);
}

public String getDataFromDataBase() throws ClassNotFoundException, SQLException
{
return new RegistrationDAO().getDataFromDataBase();
}
public boolean updateuser (RegistrationBeans rb) throws ClassNotFoundException
{

return new RegistrationDAO().updateuser(rb);
}

}
//rei dao
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.ignite.Ignite114_Career.dao;


import com.ignite.Ignite114_Career.beans.RegistrationBeans;
import com.ignite.Ignite114_Career.utils.ConnectionManager;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
*
* @author ignite114
*/
public class RegistrationDAO {

private String finalString;


public boolean updateuser(RegistrationBeans rb) throws ClassNotFoundException{
boolean saved = false;
Connection con = null;
PreparedStatement ps = null;

try {


con = new ConnectionManager().getConnection();

if(rb.getApplicant().equalsIgnoreCase("Student")){
ps = con.prepareStatement("update student where (Name=?,Email=?,Password=?, Mobile_no=?, Batch=?, Course=?, City=?, Percentage=?) ;");
ps.setString(1, rb.getS_name());
ps.setString(2, rb.getS_email());
ps.setString(3, rb.getS_pass());
// ps.setString(4,rb.getS_Course));
// ps.setString(4, rb.getS_course));
ps.setString(4, rb.getS_mobile());
ps.setString(5, rb.getS_batch());
ps.setString(6, rb.getS_course());

ps.setString(7, rb.getS_city());
// ps.setString(6, rb.getS_Per()));
ps.setString(8,rb.getS_percentage());




ps.executeUpdate();

saved = true;
}
}

catch (Exception ex) {
ex.printStackTrace();
saved = false;
} finally {
try {
if (ps != null) {
ps.close();
}
if (con != null) {
con.close();
}
} catch (SQLException ex) {
ex.printStackTrace();
}
}

return saved;

}
//insert use
public boolean insertuser(RegistrationBeans rb) throws ClassNotFoundException{
boolean saved = false;
Connection con = null;
PreparedStatement ps = null;

try {


con = new ConnectionManager().getConnection();

if(rb.getApplicant().equalsIgnoreCase("Student")){
ps = con.prepareStatement("insert into student (Name,Email,Password, Mobile_no, Batch, Course, City, Percentage) values (?,?,?,?,?,?,?,?) ;");
ps.setString(1, rb.getS_name());
ps.setString(2, rb.getS_email());
ps.setString(3, rb.getS_pass());
// ps.setString(4,rb.getS_Course));
// ps.setString(4, rb.getS_course));
ps.setString(4, rb.getS_mobile());
ps.setString(5, rb.getS_batch());
ps.setString(6, rb.getS_course());

ps.setString(7, rb.getS_city());
// ps.setString(6, rb.getS_Per()));
ps.setString(8,rb.getS_percentage());




ps.executeUpdate();

saved = true;
}


else if(rb.getApplicant().equalsIgnoreCase("Employer")){



ps = con.prepareStatement("insert into employer (Company_Name,Email,Password,Representative_Name,HeadOffice_Location, Contact_number) values (?,?,?,?,?,?) ;");
ps.setString(1, rb.getEp_name());
ps.setString(2, rb.getE_email());//email
ps.setString(3, rb.getE_pass());//pass
ps.setString(4,rb.getE_cpname());//rep name
ps.setString(5, rb.getE_office());//location
ps.setString(6, rb.getE_mob()); //number

ps.executeUpdate();

saved = true;
}


else if(rb.getApplicant().equalsIgnoreCase("Alumni")){



ps = con.prepareStatement("insert into alumni (Name,Email,Password, Mobile_No, Batch, Salary, Company_Placed) values (?,?,?,?,?,?,?) ;");
ps.setString(1, rb.getA_name());//name;
ps.setString(2, rb.getA_email());//email
ps.setString(3, rb.getA_pass());//pass
ps.setString(4,rb.getA_mob()); //mobile
ps.setString(5, rb.getA_batch());//batch
ps.setString(6, rb.getA_salary());//salary
ps.setString(7, rb.getA_comp());//comp placed


ps.executeUpdate();

saved = true;
}





} catch (Exception ex) {
ex.printStackTrace();
saved = false;
} finally {
try {
if (ps != null) {
ps.close();
}
if (con != null) {
con.close();
}
} catch (SQLException ex) {
ex.printStackTrace();
}
}

return saved;
}
// insert login



public boolean insertlogindetails(RegistrationBeans rb) throws ClassNotFoundException{
boolean saved = false;
Connection con = null;
PreparedStatement ps = null;
try {


con = new ConnectionManager().getConnection();


ps = con.prepareStatement("insert into login (email,password,usertype) values (?,?,?) ;");
ps.setString(1, rb.getEmail123());
ps.setString(2, rb.getPassword123());
ps.setString(3, rb.getApplicant());

ps.executeUpdate();

saved = true;
} catch (Exception ex) {
ex.printStackTrace();
saved = false;
} finally {
try {
if (ps != null) {
ps.close();
}
if (con != null) {
con.close();
}
} catch (SQLException ex) {
ex.printStackTrace();
}
}

return saved;
}


public String getDataFromDataBase() throws ClassNotFoundException, ClassNotFoundException, ClassNotFoundException, SQLException {
Connection con = null;
String finalString="";
PreparedStatement ps = null;
con = new ConnectionManager().getConnection();
ps = con.prepareStatement("select Name from `feedback`");

ResultSet re= ps.executeQuery();

while(re.next())
{
finalString=finalString+ re.getString("name")+",";
}
return finalString;
}

}
bean

//
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.ignite.Ignite114_Career.beans;

/**
*
* @author ignite114
*/
public class RegistrationBeans {

String s_name, s_email, s_pass, s_batch, s_course,s_city, s_mobile, s_percentage;

String ep_name, e_email, e_pass, e_comp, e_office,e_mob, e_cpname, e_number;
String a_name, a_email, a_pass, a_comp, a_mob, a_batch, a_salary;
private String Applicant;

private String email123;

private String password123;


public String getS_name() {
return s_name;
}

public void setS_name(String s_name) {
this.s_name = s_name;
}

public String getS_email() {
return s_email;
}

public void setS_email(String s_email) {
this.s_email = s_email;
}

public String getS_pass() {
return s_pass;
}

public void setS_pass(String s_pass) {
this.s_pass = s_pass;
}

public String getS_batch() {
return s_batch;
}

public void setS_batch(String s_batch) {
this.s_batch = s_batch;
}

public String getS_course() {
return s_course;
}

public void setS_course(String s_course) {
this.s_course = s_course;
}

public String getS_city() {
return s_city;
}

public void setS_city(String s_city) {
this.s_city = s_city;
}

public String getS_mobile() {
return s_mobile;
}

public void setS_mobile(String s_mobile) {
this.s_mobile = s_mobile;
}

public String getS_percentage() {
return s_percentage;
}

public void setS_percentage(String s_percentage) {
this.s_percentage = s_percentage;
}

public String getEp_name() {
return ep_name;
}

public void setEp_name(String ep_name) {
this.ep_name = ep_name;
}

public String getE_email() {
return e_email;
}

public void setE_email(String e_email) {
this.e_email = e_email;
}

public String getE_pass() {
return e_pass;
}

public void setE_pass(String e_pass) {
this.e_pass = e_pass;
}

public String getE_comp() {
return e_comp;
}

// public void setE_comp(String e_comp) {
// this.e_comp = e_comp;
// }

public String getE_office() {
return e_office;
}

public void setE_office(String e_office) {
this.e_office = e_office;
}

public String getE_mob() {
return e_mob;
}

public void setE_mob(String e_mob) {
this.e_mob = e_mob;
}

public String getE_cpname() {
return e_cpname;
}

public void setE_cpname(String e_cpname) {
this.e_cpname = e_cpname;
}

// public String getE_number() {
// return e_number;
// }

public void setE_number(String e_number) {
this.e_number = e_number;
}

public String getA_name() {
return a_name;
}

public void setA_name(String a_name) {
this.a_name = a_name;
}

public String getA_email() {
return a_email;
}

public void setA_email(String a_email) {
this.a_email = a_email;
}

public String getA_pass() {
return a_pass;
}

public void setA_pass(String a_pass) {
this.a_pass = a_pass;
}

public String getA_comp() {
return a_comp;
}

public void setA_comp(String a_comp) {
this.a_comp = a_comp;
}

public String getA_mob() {
return a_mob;
}

public void setA_mob(String a_mob) {
this.a_mob = a_mob;
}

public String getA_batch() {
return a_batch;
}

public void setA_batch(String a_batch) {
this.a_batch = a_batch;
}

public String getA_salary() {
return a_salary;
}

public void setA_salary(String a_salary) {
this.a_salary = a_salary;
}

public String getApplicant() {
return Applicant;
}

public void setApplicant(String Applicant) {
this.Applicant = Applicant;
}

public String getEmail123() {
return email123;
}

public void setEmail123(String email123) {
this.email123 = email123;
}

public String getPassword123() {
return password123;
}

public void setPassword123(String password123) {
this.password123 = password123;
}


}
//gin dao
public class LoginDAO {

public String login(LoginBeans lb) throws ClassNotFoundException, ClassNotFoundException, ClassNotFoundException, SQLException {
Connection con = null;
String finalString="";
PreparedStatement ps = null;
con = new ConnectionManager().getConnection();
ps = con.prepareStatement("select usertype from `login` where email=? and password=?");
ps.setString(1,lb.getEmail());
ps.setString(2,lb.getPassword());
ResultSet re= ps.executeQuery();
// String name="";
// String type="";
// String res="";
while(re.next())
{
finalString=finalString+ re.getString("usertype");
System.out.println("The user type is "+finalString);
}
return finalString;
}

//logout
public class LogoutServlet extends HttpServlet {


@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {


HttpSession session;
session = request.getSession(false);
String type = (String) session.getAttribute("usertype");
session.invalidate();
if (type.equalsIgnoreCase("Student")) {
response.sendRedirect("student.jsp");
}

if (type.equalsIgnoreCase("Alumni")) {
response.sendRedirect("Alumni.jsp");
}
if (type.equalsIgnoreCase("Employer")) {
response.sendRedirect("Employer.jsp");
}
}


}
//
<%
String authenticUser;
session = request.getSession(false);

if(null == session.getAttribute("email"))
{
response.sendRedirect("index.jsp");
}
else
{
authenticUser = session.getAttribute("email").toString();
// out.print("The Session Value is"+authenticUser);
session.setAttribute("useremail",authenticUser);
}

%>


















<img src=\"images/background-tcs.PNG\" alt=\"\" height=\"70px\" width=\"90px\"/>

<img src="images/background-tcs.PNG" alt="" height="70px" width="90px"/>






Integral University




Integral University










<img src="images/home.png" alt=""/>


<img src="images/linkedin.png" alt=""/>



<img src="images/facebook.png" alt=""/>


<img src="images/google+.png" alt=""/>








            Logout
<!-- Register -->











<input type=\"search\" name=\"websitesearch\" placeholder=\"Search\" style=\"width:180px; height: 27px\" />

<!-- <input type=\"imagebutton\" name=\"search\" style=\"width: 120px\" />-->

<!--



-->

<input type=\"image\" src=\"images/search.png\" style=\"float: right; margin-right: 6em; height: 26px\" />





<input type="search" name="websitesearch" placeholder="Search" style="width:180px; height: 27px" />
<!-- <input type="imagebutton" name="search" style="width: 120px" />-->
<!--

-->
<input type="image" src="images/search.png" style="float: right; margin-right: 6em; height: 26px" />

























  • Home
  • Student
  • Employer
  • Alumni
  • About Us
  • Contact Us
  • Feedback






































Search Jobs







Search Jobs








Student







<!--START MENU-->


Student




<!--START MENU-->








  • View Jobs

  • <!--
  • Edit Profile

  • -->
  • Interview Tips

  • Alumni Connect

  • View Announcements























Get the best Industry Jobs







Get the best Industry Jobs













<%@page import=\"java.sql.DriverManager\"%>

<%@page import=\"java.sql.ResultSet\"%>

<%@page import=\"java.sql.Statement\"%>

<%@pag e import=\"java.sql.Connection\"%>



<%

// String id = request.getParameter(\"email\");

\tString driverName = \"com.mysql.jdbc.Driver\";

\tString connectionUrl = \"jdbc:mysql://localhost:3306/\";

\tString dbName = \"ignite114_careercorner\";

\tString userId = \"root\";

\tString password = \"root\";

\t

\ttry {

\t\tClass.forName(driverName);

\t} catch (ClassNotFoundException e) {

\t\te.printStackTrace();

\t}

\t

\tConnection connection = null;

\tStatement statement = null;

\tResultSet resultSet = null;

%>



View Jobs



<%

\ttry{\t

\t\tconnection = DriverManager.getConnection(connectionUrl+dbName, userId, password);

\t\tstatement=connection.createStatement();

\t\tString sql =\"SELECT * FROM postjob\";



\t\tresultSet = statement.executeQuery(sql);

\t\twhile(resultSet.next()){

%>

<!-- -->

<%\t\t

\t\t}

\t\t

\t} catch (Exception e) {

\t\te.printStackTrace();

\t}

%>



\t\t\t\t\t\t\t\t\t
Job IdJob TitleFunctional AreaSalaryQualificationInterview_Date Apply
<%=resultSet.getString(\"Id\") %> <%=resultSet.getString(\"Job_Title\") %><%=resultSet.getString(\"Functional_Area\") %><%=resultSet.getString(\"Salary\") %><%=resultSet.getString(\"Qualification\") %> <%=resultSet.getString(\"Interview_Date\") %> <img src=\"images/1400341189_OK.png\" alt=\"apply jobs\"><%--<%=resultSet .getString(\"Interview_Date\") %>--%>







<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.Connection"%>

<%
// String id = request.getParameter("email");
String driverName = "com.mysql.jdbc.Driver";
String connectionUrl = "jdbc:mysql://localhost:3306/";
String dbName = "ignite114_careercorner";
String userId = "root";
String password = "root";

try {
Class.forName(driverName);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}

Connection connection = null;
Statement statement = null;
ResultSet resultSet = null;
%>

View Jobs

<%
try{
connection = DriverManager.getConnection(connectionUrl+dbName, userId, password);
statement=connection.createStatement();
String sql ="SELECT * FROM postjob";

resultSet = statement.executeQuery(sql);
while(resultSet.next()){
%>
<!-- -->
<%
}

} catch (Exception e) {
e.printStackTrace();
}
%>

Job IdJob TitleFunctional AreaSalaryQualificationInterview_Date Apply
<%=resultSet.getString("Id") %> <%=resultSet.getString("Job_Title") %> <%=resultSet.getString("Functional_Area") %> <%=resultSet.getString("Salary") %> <%=resultSet.getString("Qualification") %> <%=resultSet.getString("Interview_Date") %> <img src="images/1400341189_OK.png" alt="apply jobs"><%--<%=resultSet.getString("Interview_Date") %>--%>

推荐答案

这篇关于MVC结构解释了全部服务n的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆