Rajaguru Ramalingam

Greenhorn
+ Follow
since Apr 12, 2004
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Rajaguru Ramalingam

Hi Everyone,

Assume, my Stored procedure returns 10 values of same type.If i din't keep that as array, i can use the cursor otherwise. If it is the case, how to handle the cursor which has values of same type in my java-jdbc programming?

Thanks in advance.
How can i access a servlet from another servlet which is part of another web application or servlet context....?
19 years ago
How can i access a servlet which is in different servletcontext or webapplication? can anyone explain me the process?
19 years ago
Hi Josephine,

Let me assume that u have 3 fields as one record...and you are displaying each records with one checkbox.These records are shown using Jsp.While displaying every record , hope you will be using one "for loop" and adding the checkbox at the right end or left end of the row.Each record would have one primary key value ..say for example..employee number or something..so you can have the primary key value of each record as the check box values(ex:emp no) and checkbox name as some useful text.

so , while displaying 10 records, you will have 10 checkboxes which has 10 unique values...right?..now..u r ticking some check boxes...and submitting this form to a servlet...you can get the ticked check box values at the servlet using getParameterValues()..This function will return an array of all the unique values of checkboxes...right?...then u can execute the delete query in a "for loop" ,using these unique values in where condition to delete the records from the table..

Hope , you could have understood the flow .
19 years ago
JSP
What is your problem buddy?
19 years ago
Thanks Bear, I will be careful hereafter...
19 years ago
JSP
Regarding ur problem,
1) Don't add the page directive in the chineese.jsp
2) Add the following 2 lines in the container jsp which includes that chineese.jsp
<%@ page contentType="text/html; charset=UTF-8" %>
<% request.setCharacterEncoding("UTF-8");%>
Hope this will solve ur problem.
19 years ago
JSP
The differences are
1) In Jsp, content generation and content presentation are easily separable..so readablity is easy But in Servlet..we need to embed the Html in java code which is difficult to understand.
2) Jsp gives Http protocol specific functionality only.But servlet may provide Protocol independent functionality that is , servlet may be a http servlet or generic servlet
3) Jsp is an extension of servlet.
19 years ago
JSP
Tejaswini,
You need , one jsp,one servlet.
In the jsp page, put two text boxes and a submit button and in the form action..leads to the servlet. In the servlet service method..check the username and pwd validity by querying the database..if exists..use sendredirect funtion to redirect the browser to the welcome page other wise to the error page...if the user id , password are correct then , store them in the session..so that..in every successive page, we can check the user validity..so user can not be allowed to access the other pages by directly putting the url in the browser...
Practise it ..then only u will realise the thing.
19 years ago
JSP
I suppose, the problem is , he needs to include a jsp page in to a container jsp, that included jsp expects a request parameter value and that value is dynamic and it is generated from the container page...right???
but solution...im thinking.......other than the specified one already...
19 years ago
JSP
<%@ page errorPage="error.jsp" %>
<jsp:useBean id="prop" scope="page" class="java.util.Properties" />
<%@ page import="java.io.*,java.util.*,javax.servlet.*" %>
<%!
public String getBoundary(HttpServletRequest request,Properties prop) throws ServletException,IOException{
String boundary = null;
Enumeration enum = request.getHeaderNames();
while(enum.hasMoreElements()){
String header = (String)enum.nextElement();
String hvalue = request.getHeader(header);
prop.setProperty((header).toLowerCase(),hvalue);
if( "content-type".equalsIgnoreCase(header) ){
int idx = hvalue.lastIndexOf("boundary=");
if( idx != -1 ){
boundary= hvalue.substring( idx+9 , hvalue.length());
}
}
}
return boundary;
}
public String getFileName(String secondline){
int len = secondline.length();
int idx = secondline.lastIndexOf("filename=");
if( idx == -1 ) return null;
String filename = secondline.substring( idx+10 , len-1);
filename = "null"; //filename.replace('\\','/');
idx = filename.lastIndexOf("/");
idx = idx + 1;
filename = filename.substring( idx );
return filename;
}
%>
<%
String DPATH = "C:\\temp\\file\\";
int ROUGHSIZE=1024;
int MAXSIZE = 10; // Mega Byte
String boundary = getBoundary(request,prop);
if( boundary == null ){
boundary = prop.getProperty("boundary");// This statement line for HOTJAVABROWSER 3.0
}else{
boundary = "--"+boundary;
}
if( boundary == null ){
throw new Exception("BNF");
}
Long contentsize = new Long(prop.getProperty("content-length","0"));
int c;
StringWriter st = new StringWriter();
if( contentsize.longValue() < 1L ){
throw new Exception("ZERO");
}
long l = contentsize.longValue() - ROUGHSIZE;
/*
You can restrict upload file size in the following way
1. after uploaded u cannt find out file size then display error message
2. from contentsize it will give approximate size of file in bytes.
based on this u can restrict uploading.
*/
int KB = 1024;
int MB = 1024 * KB;
int csize = (int)(l / MB);
if( csize > MAXSIZE ){
throw new Exception("EL");
}
ServletInputStream fin = request.getInputStream();
//Getting Start Boundary Line
int cn;
int count=0;
while( (c=fin.read()) != -1 ){
if( c == '\r') break;
st.write(c);
count++;
}
c=fin.read();//read new line
String tboundary = st.getBuffer().toString();
tboundary=tboundary.trim();
if( ! tboundary.equalsIgnoreCase( boundary) ){
throw new Exception("BBNF");
}
st.close();
st = null;
st = new StringWriter();
//Getting File Information
while( (c=fin.read()) != -1 ){
if( c == '\r' ) break;
st.write(c);
}
c=fin.read();//read new line
String secondline = st.getBuffer().toString();
String filename = getFileName(secondline);
st.close();
st = null;
st = new StringWriter();
//Read Content Type of File
while( (c=fin.read()) != -1 ){
if( c == '\r' ) break;
st.write( c );
}
c=fin.read();//read new line
//out.println( st.getBuffer().toString() );
//Read \r and \n character
fin.read();
fin.read();
File newfile = null;
FileOutputStream fout =null;
try{
if( filename == null ) throw new FileNotFoundException("File Name not found");
newfile = new File(DPATH+filename);
fout = new FileOutputStream( newfile );
}catch(FileNotFoundException fnexp){
fin.close();
throw new Exception("FNF");
}
byte b[] = null;
while( l > 1024L ){
b = new byte[1024];
fin.read(b,0,1024);
fout.write(b);
b=null;
l -= 1024L;
}
if( l > 0 ){
b = new byte[(int)l];
fin.read(b,0,(int)l);
fout.write(b);
}

ByteArrayOutputStream baos = new ByteArrayOutputStream();
while( (c = fin.read()) != -1 ){
baos.write(c);
}
String laststring = baos.toString();
int idx = laststring.indexOf(boundary);
b = baos.toByteArray();
if( idx > 2 ){
fout.write(b,0,idx-2);
}else
{
fout.close();
newfile.delete();
throw new Exception("EBNF");
}
fout.flush();
fout.close();
fin.close();
%>
19 years ago
JSP