Some general qn and Login and Redirecting help
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   lw_l
Posted On:   Sunday, January 1, 2006 02:37 AM

Hi everyone.. I am a newbie in this and need some help here in this two part of my coding.. 1 : Do i need to restart tomcat after everytime i do some editing in my servlet? Cos it seems quite troublesome and the changes are not capture if i do not restart. Or can u guys actually tell me when is the time i MUST restart tomcat and when is not necessary? 2 : In my jsp page, if i did not enter any field it can still login? how is this so? is there anything wrong with my coding(codes below) jsp-user input text field:  AdminNo:  Password: servlet-doing the validation: pub   More>>


Hi everyone.. I am a newbie in this and need some help here in this two part of my coding..


1 : Do i need to restart tomcat after everytime i do some editing in my servlet? Cos it seems quite troublesome and the changes are not capture if i do not restart. Or can u guys actually tell me when is the time i MUST restart tomcat and when is not necessary?


2 : In my jsp page, if i did not enter any field it can still login? how is this so? is there anything wrong with my coding(codes below)


jsp-user input text field:



 AdminNo:







 Password:






servlet-doing the validation:

public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, java.io.IOException
{

String userName = request.getParameter("studId");

String password = request.getParameter("studPwd");


HttpSession session = request.getSession(true);

session.setAttribute("studAdmin",userName);


if (userName==null || password==null)

{

request.setAttribute("errorNull", "yes");// if null, will return to the login page

RequestDispatcher rd = request.getRequestDispatcher("studentLogin.jsp");

rd.forward(request, response);

}

else

{

//as for below, if both fields are not null, it will retrieve from DB and validate

//part continues work


3 : Problem with RequestDispatcher

I am doing a change password, when the application runs, the changed pwd is udpated in the DB but is redirected to the wrong page.

For this part the check for null value thing also not working..(below is the coding for my change pwd servlet)


import java.io.*;

import javax.servlet.*;

import javax.servlet.http.*;

import java.sql.*;


public class studChangePwdServlet extends HttpServlet
{

public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, java.io.IOException
{


String oldPass = request.getParameter("oldPwd");

String newPass = request.getParameter("newPwd");

String confirmPass = request.getParameter("confirmPwd");


HttpSession session = request.getSession(false);

Object studAdmin = session.getAttribute("studAdmin");

String adminNo;

adminNo = studAdmin.toString();


if (oldPass==null || newPass==null || confirmPass==null)
{

RequestDispatcher rd = request.getRequestDispatcher("studChangePwd.jsp");

request.setAttribute("nullValue", "yesNull");

rd.forward(request, response);

}

else

{


try

{

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

//create the connection

Connection con = DriverManager.getConnection("jdbc:odbc:SEE");

Statement s = con.createStatement();

String sql="select studPwd from studAcc where studAcc.studId='"+adminNo+"'";

ResultSet rs=s.executeQuery(sql);

String studPwd ="";


while (rs.next())

{

studPwd = rs.getString("studPwd");

}

rs.close();


if (oldPass.equals(studPwd) && newPass.equals(confirmPass)) {


String sql1="UPDATE studAcc SET studPwd='"+newPass+"' where studId='"+adminNo+"'";


ResultSet rs1=s.executeQuery(sql1);


rs1.close();

s.close();

con.close();


RequestDispatcher rd1 = request.getRequestDispatcher("pwdChanged.jsp");

//when pwd is successfully updated, it should be directed to this page, instead it actuall redirect to here *

rd1.forward(request, response);

}

else

{

RequestDispatcher rd2 = request.getRequestDispatcher("studChangePwd.jsp");

//* it redirected to here instead

request.setAttribute("error", "yes");

rd2.forward(request, response);

}

}

catch (Exception e)

{

request.setAttribute("SQLError", e);

RequestDispatcher rd3 = request.getRequestDispatcher("studChangePwd.jsp");

rd3.forward(request, response);

}

}

}

}



PS: sorry if it's untidy(first time posting something here =D )



Regards;
lw

   <<Less
About | Sitemap | Contact