GeeCON Prague 2014*
The moose likes Servlets and the fly likes need help java servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Servlets
Bookmark "need help java servlet" Watch "need help java servlet" New topic
Author

need help java servlet

al amin
Greenhorn

Joined: Mar 03, 2009
Posts: 3
Hi

I want to filter web domin and page content using servlet. Please help me
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

What do you mean by "filter"?


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
al amin
Greenhorn

Joined: Mar 03, 2009
Posts: 3
filter means check explicit word
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Do you mean you want to use a Serlvet to remove word from some static content? Or do you want to filter something by a word, or words, submitted by the client? When you say "web domain" what filtering were you hoping for there?
al amin
Greenhorn

Joined: Mar 03, 2009
Posts: 3
I'm giving you sample code that will be understand

public class ProxyRequest extends HttpServlet
{
protected void doGet(HttpServletRequest req, HttpServletResponse res)throws ServletException, IOException

{
res.setContentType("text/html");
PrintWriter out=res.getWriter();

String line;
StringBuffer sb=new StringBuffer(req.getRequestURL());
String s=sb.toString();

out.println("<html>");
out.println("<body>");
out.println("<h1>Hello User,</1>");
out.println("yur requested url is:<br>");
out.println("<BR><BR><BR><BR><BR><BR><BR><BR>");

check_in_file x=new check_in_file();
String isOK=x.checklist(s);
if(isOK.compareTo("yes")==0)
{


out.println("body bgcolor=9995544");
out.println("<center>");
out.println("<br><br><br>");
out.println("<h1>Sorry Yucan't Access This url<br></h1>");


}
else
{
Engine y=new Engine();
int point= y.search(s);
if (point<=10)
{
res.sendRedirect(res.encodeRedirectURL(s+"?direct"));
}
else
{
File file1=new file("c://list.txt");
FileOutputStream fos=new FileOutStream(file,true);
PrintWriter pw=new PrintWriter(fos,true);
pw.println();
pw.print(s);
pw.close();

out.println("<body bgcolor=995544>");
out.println("<center>");
out.println("<br><br<br>>");
out.println("</body>");
}
}
out.println("</body>");
out.println("</html>");
}
protected void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException,IOException
{
doGet(req,res);
}
}
///////////////////////////////////////////////////////////
public class Engine
{
public int search (String url) throws IOException
{
int point=0;

ArrayList<String> max=new ArrayList<String>();
ArrayList<String> med=new ArrayList<String>();
ArrayList<String> min=new ArrayList<String>();


max.add("analsex");
max.add("boobs");
max.add("booty");
max.add("chicos");
max.add("cock");
max.add("dicks");
max.add("dildo");
max.add("erection");
max.add("erotic");



med.add("alsscan");
med.add("amateur");
med.add("anaal");
med.add("babes");
med.add("barely-legal");
med.add("bbw");
med.add("bdsm");
med.add("beaver");
med.add("belle");
med.add("bikini");



min.add("celeb");
min.add("centerfold");
min.add("cheating");
min.add("cherry");
min.add("clit");
min.add("crazy");
min.add("drunk");
min.add("femalesex");
min.add("mom");
min.add("girl");
min.add("teen");

String line;
URL hp=new URL(url);
URLConnection hpcon=hp.openConnection();
int len=hpcon.getContentLength();

if(len!=0)
{
InputStream input=hpcon.getInputStream();
InputStreamReader isr=new InputStreamReader(input);
BufferedReader br=new BufferedReader(isr);

line=br.readLine();

while(line != null)
{

StringTokenizer st=new StringTokenizer(line,"\t\n\f+.='<>{}[]:;?+-_!~@#$%|^&*?|\\ /");

while(st.hasMoreTokens())
{
String t=st.nextToken();

for(int x=0; x< max.size();x++)
{
if(max.get(x).equalsIgnoreCase(t)){
point+=3;}
}



for(int y=0;y< med.size();y++)
{

if(med.get(y).equalsIgnoreCase(t))
{
point+=2;
}

}

for(int k=0; k< min.size(); k++)
{
if(min.get(k).equalsIgnoreCase(t))
{
point+=1;
}
}
}
}

line = br.readLine();


input.close();
}
return point;
}
}

/////////////////////////////////////////////////////////

public class check_in_file
{
public String checklist(String u) throws IOException
{
String line;
int flag=0;
File file=new File("c://list.txt");
FileInputStream fis=new FileInputStream(file);
InputStreamReader isr=new InputStreamReader(fis);
BufferedReader br= new BufferedReader(isr);
line = br.readLine();

while(line != null)
{
if(line.compareTo(u)==0)

{
flag=1;
return "yes";
}
line = br.readLine();
}
if(flag!=1)
{
return "no";
}
return "no";
}



}
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Ok not I understand. When it comes to custom security constraints a Filter is a better choice than a Servlet. This way any request to your web appliction can be checked and re-routed accordingly.

You pseudo-code would be something like:

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61315
    
  66

Please be sure to take the time to compose descriptive subjects for your posts; read this for more information.

Using a title of "need help java servlet" in a forum completely dedicated to questions on Servlets isn't very helpful.

Please go back and change your post to add a more meaningful subject by clicking the

Also, please be sure to use code tags when posting code to the forums. Unformatted code is extremely hard to read and many people that might be able to help you will just move along to posts that are easier to read. Please read this for more information.

You can go back and change your post to add code tags by clicking the button on your post.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: need help java servlet