0% found this document useful (0 votes)
8 views26 pages

Sample Code

The document contains Java classes for a web application that manages user registration, login, profile updates, and tweet composition. It includes database connection handling, user input processing, and validation against a list of inappropriate words. Key functionalities include user registration, login checks, profile updates, and tweet posting with image uploads.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views26 pages

Sample Code

The document contains Java classes for a web application that manages user registration, login, profile updates, and tweet composition. It includes database connection handling, user input processing, and validation against a list of inappropriate words. Key functionalities include user registration, login checks, profile updates, and tweet posting with image uploads.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

DBConnection.

java
package [Link];

import [Link];

import [Link];

/**

* @author Sumathi

*/

public class DBConnection {

public static Connection con = null;

public static Connection getDBConnection(){

try {

[Link]("[Link]");

con =
[Link]("jdbc:mysql://localhost:3306/spam","root","root");

if(con!=null){

return con;

}else{

[Link]("Connection object is Null");

} catch (Exception e) {

[Link]("DB Class Error");

[Link]();

}finally{

try {

//[Link]();

} catch (Exception e) {

return con;
}

[Link]
package [Link];

import [Link];

import [Link];

import [Link];

import [Link];

import [Link];

import [Link];

import [Link];

import [Link];

import [Link];

import [Link];

import [Link];

import [Link];

/**

* @author Sumathi

*/

@MultipartConfig

public class userregisteraction extends HttpServlet {

@Override

protected void doPost(HttpServletRequest request, HttpServletResponse response)

throws ServletException, IOException {


//processRequest(request, response);

PrintWriter out = [Link]();

String name = [Link]("Username");

String email = [Link]("Email");

String password = [Link]("password");

String dob = [Link]("DOB");

String state = [Link]("State");

String country = [Link]("Country");

Part filepart = [Link]("Profile_img");

InputStream is = [Link]();

String ImageName = [Link]();

Connection con = null;

PreparedStatement ps = null;

try {

con = [Link]();

String sqlQuery = "insert into


userregister(name,email,password,dob,state,country,image) values(?,?,?,?,?,?,?)";

ps = [Link](sqlQuery);

[Link](1, name);

[Link](2, email);

[Link](3, password);

[Link](4, dob);

[Link](5, state);

[Link](6, country);

[Link](7, is);

int no = [Link]();
if (no > 0) {

[Link]("[Link]?msg=Success");

} else {

[Link]("[Link]?msg=failed");

} catch (Exception e) {

[Link]();

[Link]("[Link]?msg=Exist");

} finally {

try {

[Link]();

[Link]();

} catch (Exception e) {

[Link]
package [Link];

import [Link];

import [Link];

import [Link];

import [Link];

import [Link];
import [Link];

import [Link];

import [Link];

import [Link];

import [Link];

import [Link];

/**

* @author Sumathi

*/

public class userlogincheck extends HttpServlet {

/**

* Processes requests for both HTTP <code>GET</code> and <code>POST</code>

* methods.

* @param request servlet request

* @param response servlet response

* @throws ServletException if a servlet-specific error occurs

* @throws IOException if an I/O error occurs

*/

protected void processRequest(HttpServletRequest request, HttpServletResponse


response)

throws ServletException, IOException {

[Link]("text/html;charset=UTF-8");

PrintWriter out = [Link]();

String email = [Link]("email");


String pswd = [Link]("password");

Connection con = null;

PreparedStatement ps = null;

ResultSet rs = null;

String status = null;

HttpSession hs = [Link]();

try {

con = [Link]();

String sqlQury = "select * from userregister where email = ? and password = ?";

ps = [Link](sqlQury);

[Link](1, email);

[Link](2, pswd);

rs = [Link]();

if ([Link]()) {

String sts = [Link]("logistatus");

if ([Link]("normal")) {

[Link]("username", [Link]("name"));

[Link]("email", [Link]("email"));

[Link]("[Link]?msg=Login Success");

} else {

[Link]("[Link]?msg=spammer");

} else {

[Link]("[Link]?msg=failed");

} catch (Exception ex) {


[Link]();

[Link]("[Link]?msg=notexist");

@Override

protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws


ServletException, IOException {

processRequest(req, resp); //To change body of generated methods, choose Tools |


Templates.

@Override

protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws


ServletException, IOException {

processRequest(req, resp);

[Link]
package [Link];

import [Link];

import [Link];

import [Link];

import [Link];

import [Link];

import [Link];

/**

*
* @author Sumathi

*/

public class adminlogincheck extends HttpServlet {

/**

* Processes requests for both HTTP <code>GET</code> and <code>POST</code>

* methods.

* @param request servlet request

* @param response servlet response

* @throws ServletException if a servlet-specific error occurs

* @throws IOException if an I/O error occurs

*/

protected void processRequest(HttpServletRequest request, HttpServletResponse


response)

throws ServletException, IOException {

[Link]("text/html;charset=UTF-8");

PrintWriter out = [Link]();

String UserName = [Link]("user");

String pswd = [Link]("password");

if ([Link]("admin") && [Link]("admin")) {

[Link]("[Link]?msg=success");

} else {

[Link]("[Link]?msg=filed");

// <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on


the left to edit the code.">
/**

* Handles the HTTP <code>GET</code> method.

* @param request servlet request

* @param response servlet response

* @throws Servlet Exception if a servlet-specific error occurs

* @throws IOException if an I/O error occurs

*/

@Override

protected void doGet(HttpServletRequest request, HttpServletResponse response)

throws ServletException, IOException {

processRequest(request, response);

/**

* Handles the HTTP <code>POST</code> method.

* @param request servlet request

* @param response servlet response

* @throws ServletException if a servlet-specific error occurs

* @throws IOException if an I/O error occurs

*/

@Override

protected void doPost(HttpServletRequest request, HttpServletResponse response)

throws ServletException, IOException {

processRequest(request, response);

}
/**

* Returns a short description of the servlet.

* @return a String containing servlet description

*/

@Override

public String getServletInfo() {

return "Short description";

}// </editor-fold>

[Link]
package [Link];

import [Link];

import [Link];

import [Link];

import [Link];

import [Link];

import [Link];

import [Link];

import [Link];

import [Link];

import [Link];

import [Link];

import [Link];

/**
*

* @author Sumathi

*/

@MultipartConfig

public class UserUpdateProfile extends HttpServlet {

@Override

protected void doPost(HttpServletRequest request, HttpServletResponse response)

throws ServletException, IOException {

int id = [Link]([Link]("userid"));

String username = [Link]("username");

String state = [Link]("state");

String country = [Link]("country");

Part filePart = [Link]("profilepic");

InputStream is = [Link]();

Connection con = null;

PreparedStatement ps = null;

try {

con = [Link]();

String sqlQuery = "update userregister set name = ?, state=?,country=?, image=?


where id=?";

ps = [Link](sqlQuery);

[Link](1, username);

[Link](2, state);

[Link](3, country);

[Link](4, is);

[Link](5, id);
[Link]();

[Link]("[Link]?msg=Profile Updated");

} catch (Exception e) {

[Link]("Error at " + [Link]());

} finally {

try {

[Link]();

[Link]();

} catch (Exception e) {

/**

* Returns a short description of the servlet.

* @return a String containing servlet description

*/

@Override

public String getServletInfo() {

return "Short description";

}// </editor-fold>

[Link]
package [Link];

import [Link];

import [Link];
import [Link];

import [Link];

import [Link];

import [Link];

import [Link];

import [Link];

import [Link];

import [Link];

import [Link];

import [Link];

/**

* @author Sumathi

*/

@MultipartConfig

public class UserComposeTweets extends HttpServlet {

/**

* Handles the HTTP <code>POST</code> method.

* @param request servlet request

* @param response servlet response

* @throws ServletException if a servlet-specific error occurs

* @throws IOException if an I/O error occurs

*/

@Override

protected void doPost(HttpServletRequest request, HttpServletResponse response)


throws ServletException, IOException {

String user = [Link]("user");

String usremail = [Link]("usremail");

String tweet = [Link]("tweet");

Part filePart = [Link]("bpo");

InputStream is = [Link]();

[Link] cdate = new [Link](new [Link]().getTime());

Connection con = null;

PreparedStatement ps = null;

try {

con = [Link]();

String sql = "insert into tweets(username,usremail,tweet,tweetimg,cdate)


values(?,?,?,?,?)";

ps = [Link](sql);

[Link](1, user);

[Link](2, usremail);

[Link](3, tweet);

[Link](4, is);

[Link](5, cdate);

int no = [Link]();

if (no > 0) {

[Link]("[Link]?msg=success");

} else {

[Link]("[Link]?msg=failed");

} catch (Exception e) {
[Link]("Error at " + [Link]());

[Link]("[Link]?msg=failed");

} finally {

try {

[Link]();

[Link]();

[Link]();

} catch (Exception e) {

/**

* Returns a short description of the servlet.

* @return a String containing servlet description

*/

@Override

public String getServletInfo() {

return "Short description";

}// </editor-fold>

[Link]
package [Link];

/**

* @author Sumathi
*/

public class AlgorithmWorkFlow {

public String[] words = {" Dirty", "stupid", "idiot", "anus", "Prick ", "good", "ass-hat",
"Shit", "unpleasant", "wasted", "Gobdaw", "Teigh go dtí ifreann", "Merde", "Bastard",
"Damn,Stupider ", "assmonkey", "hard on", "handjob", "hell", "ho", "hoe", "kooch",
"lameass", "loser", "lesbo", "schlong", "worst", "shithouse", "shittiest", "skank", "dirty girl",
"dirty boy", "tit", "tard", "bla"};

public int catagoriseTweet(String tweet) {

int count = 0;

int len = 0;

String[] t = [Link](" ");

//[Link]([Link] + "==" + [Link]);

int wrdsLen = [Link];

int twtLen = [Link];

if (wrdsLen <= twtLen) {

//[Link]("AM WOrds Array " + wrdsLen);

for (int i = 0; i < wrdsLen; i++) {

for (int j = 0; j < twtLen; j++) {

if (words[i].equalsIgnoreCase(t[j])) {

[Link]("Volgur Word is " + words[i]);

count++;

} else if (twtLen <= wrdsLen) {

//[Link]("AM Tweet Array " + twtLen);

for (int i = 0; i < twtLen; i++) {


for (int j = 0; j < wrdsLen; j++) {

if (t[i].equalsIgnoreCase(words[j])) {

[Link]("VVolgur word is " + t[i]);

count++;

} else {

[Link]("Both are Equal Length " + twtLen);

for (int i = 0; i < twtLen; i++) {

for (int j = 0; j < wrdsLen; j++) {

if (t[i].equalsIgnoreCase(words[j])) {

count++;

return count;

public static void main(String[] args) {

AlgorithmWorkFlow awf = new AlgorithmWorkFlow();

String tweet = "write stress free with the special form cutie pi doll kattamma kathi
broke field rubber grip.. bla blab lbal abla bla bla bla blab bla bla blab lbal abla bla bla bla
blab bla ";

int count = [Link](tweet);

[Link]("Count = " + count);

}
}

[Link]
package [Link];

import [Link];

/**

* @author Sumathi

*/

public class TestUrlEncode {

public static void main(String args[]) throws Exception {

URL u = new URL("[Link]

[Link]("The URL is " + u);

[Link]("The scheme is " + [Link]());

[Link]("The user info is " + [Link]());

String host = [Link]();

if (host != null) {

int atSign = [Link]('@');

if (atSign != -1) {

host = [Link](atSign + 1);

[Link]("The host is " + host);

} else {

[Link]("The host is null.");

[Link]("The port is " + [Link]());


[Link]("The path is " + [Link]());

[Link]("The ref is " + [Link]());

[Link]("The query string is " + [Link]());

[Link]
package [Link];

import [Link];

import [Link];

import [Link];

import [Link];

/**

* @author Sumathi

*/

public class URLFiltersAlgorithm {

String[] urls = {"[Link] "[Link]


"[Link] "[Link] "[Link]
"[Link] "[Link] "[Link]
"[Link] "[Link] "[Link]
"[Link] "[Link] "[Link]
"[Link] "[Link] "[Link]
"[Link]

public static boolean isValid(String url) {

try {

new URL(url).toURI();

return true;

} catch (Exception e) {
return false;

public int checkUrlsAvailability(String tweet) {

int count = 0;

String[] tweet_array = [Link](" ");

for (int i = 0; i < tweet_array.length; i++) {

//[Link](tweet_array[i]);

if (isValid(tweet_array[i])) {

//[Link]("Yes");

String url_is = tweet_array[i];

[Link]("Bla " + url_is);

for (int u = 0; u < [Link]; u++) {

if (urls[u].equalsIgnoreCase(url_is)) {

count++;

} else {

//[Link]("No");

return count;

public static void main(String[] args) {

URLFiltersAlgorithm u = new URLFiltersAlgorithm();


String ss = "this is awesome url so that its gonna take some huge ammount of
predection bla bla [Link]

int c = [Link](ss);

[Link]("Count is " + c);

[Link]
package [Link];

import [Link];

import [Link];

import [Link];

import [Link];

/**

* @author Sumathi

*/

public class UsersUtility {

private Connection con = null;

private PreparedStatement ps = null;

private ResultSet rs = null;

public int getUserId(String email) {

int usrID = 0;

try {

con = [Link]();

String sql = "select id from userregister where email = ?";

ps = [Link](sql);
[Link](1, email);

rs = [Link]();

[Link]();

usrID = [Link]("id");

} catch (Exception e) {

[Link]("Error at " + [Link]());

} finally {

try {

[Link]();

[Link]();

[Link]();

} catch (Exception e) {

return usrID;

public String getUserName(String email) {

String name = null;

try {

con = [Link]();

String sql = "select name from userregister where email = ?";

ps = [Link](sql);

[Link](1, email);

rs = [Link]();

[Link]();

name = [Link]("name");
} catch (Exception e) {

[Link]("Error at " + [Link]());

} finally {

try {

[Link]();

[Link]();

[Link]();

} catch (Exception e) {

return name;

public String getTweetDescription(int tweetid) {

String tweet = null;

try {

con = [Link]();

String sql = "select tweet from tweets where id = ?";

ps = [Link](sql);

[Link](1, tweetid);

rs = [Link]();

[Link]();

tweet = [Link]("tweet");

} catch (Exception e) {

[Link]("Error at " + [Link]());

} finally {

try {
[Link]();

[Link]();

[Link]();

} catch (Exception e) {

return tweet;

public void updateUserStatus(String usrEmail) {

String sts = "spammer";

try {

con = [Link]();

String sqlQuery = "update userregister set spamstatus = ? where email = ?";

ps = [Link](sqlQuery);

[Link](1, sts);

[Link](2, usrEmail);

[Link]();

} catch (Exception e) {

[Link]("Error AT Update User Spam Status " + [Link]());

} finally {

try {

[Link]();

[Link]();

} catch (Exception e) {

}
}

public String getUserStatus(int id) {

String status = null;

try {

con = [Link]();

String sql = "select spamstatus from userregister where id = ?";

ps = [Link](sql);

[Link](1, id);

rs = [Link]();

[Link]();

status = [Link]("spamstatus");

} catch (Exception e) {

[Link]("Error at " + [Link]());

} finally {

try {

[Link]();

[Link]();

[Link]();

} catch (Exception e) {

return status;

public String getUserBlockingStatus(int id) {

String status = null;

try {
con = [Link]();

String sql = "select logistatus from userregister where id = ?";

ps = [Link](sql);

[Link](1, id);

rs = [Link]();

[Link]();

status = [Link]("logistatus");

} catch (Exception e) {

[Link]("Error at " + [Link]());

} finally {

try {

[Link]();

[Link]();

[Link]();

} catch (Exception e) {

return status;

You might also like