anuj khanna

Greenhorn
+ Follow
since Jan 11, 2001
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by anuj khanna

hi,
i'm trying to use MultipartRequest but i'm getting exception
java.io.IOException: Posted content type isn't multipart/form-data
at com.oreilly.servlet.multipart.MultipartParser.(MultipartParser.java:119)
at com.oreilly.servlet.multipart.MultipartParser.(MultipartParser.java:83)
at com.oreilly.servlet.MultipartRequest.(Compiled Code)
at pt.doPost(Compiled Code)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:747)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:840)
at sun.servlet.http.HttpServerHandler.sendResponse(HttpServerHandler.java:165)
at sun.servlet.http.HttpServerHandler.handleConnection(Compiled Code)
at sun.servlet.http.HttpServerHandler.run(Compiled Code)
at java.lang.Thread.run(Thread.java:479)
i'm using servletrunner inJSDK and i've put the com.jar file in jdk1.2.1\jre\lib\ext folder
what shall i do how shall i run the program the code of the program is
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import com.oreilly.servlet.MultipartRequest;

public class pt extends HttpServlet{
public void doPost(HttpServletRequest req,HttpServletResponse res)
throws ServletException,IOException{
res.setContentType("text/html");
PrintWriter out=res.getWriter();
try{

MultipartRequest multi=new MultipartRequest(req,"f:/avoidmiddleman",1024*1024);
out.println("<HTML>");
out.println("<HEAD><TITLE>Upload File</TITLE></HEAD>");
out.println("<BODY>");
out.println("<H1>UploadTest</H1>");
out.println("<H3>Params:</H3>");
out.println("<PRE>");
Enumeration params=multi.getParameterNames();

while(params.hasMoreElements()){

String name=(String)params.nextElement();
System.out.println(multi.getContentType(name));
String value=multi.getParameter(name);
out.println(name+"="+value);
}
out.println("</PRE>");
//show which file we received
out.println("<H3>Files:</H3>");
out.println("<PRE>");
Enumeration files =multi.getFileNames();
while(files.hasMoreElements())
{
String name=(String)files.nextElement();
String filename=multi.getFilesystemName(name);
String type=multi.getContentType(name);
File f=multi.getFile(name);
out.println("name:"+name);
out.println("filename:"+filename);
out.println("type:"+type);
if(f != null){
out.println("length:"+f.length());
out.println();
}
out.println("</PRE>");
}
}
catch(Exception ex)
{
out.println("<PRE>");
ex.printStackTrace(out);
out.println("anuj khanna");
out.println("</PRE>");
}
out.println("</BODY></HTML>");
}
}


please help fast.very very urgent.thankyou.
23 years ago
actually i wanna run my servlet on the net.my service provider is not helping me in this regard.so if u can please guide me.what's the procedure of running the servlet on net.
23 years ago
how can i deploy a servlet on the net.
23 years ago
hi
i think req.getParameter()
will help you.(req is an object of HttpServletRequest)
23 years ago
hi,
i'm not sure how to pass the value from the applet to the web-page but don't u think if u're able to pass a value to the HTML page u're actually making a dynamic page from an applet ,and i suppose a servlet is supposed to do this,generate a dynamic page
23 years ago
hi friend ,
what i could understand from your mail was that u wanna know wether u can do applet-servlet communication without using this meta tag of yours.well
there're three ways to carry out applet servlet communication
raw socket
http socket
RMI--serialized objects
well telling u about http communication
in the applet
make a URL object
URL url=new ("location of the servlet");
URLConnection con=url.openConnection();//open a connection
con.setDoOutput(true);
con.setDoIntput(true);
con.setUseCaches(false);
con.setRequestProperty("content type","application/x-www-urlencoded");
BufferedReader br=new BufferedReader(new IntputStreamReader(con.getInputStream()));//depends on your choice what u wanna use
then read the content from the servlet using readLine()or what ever u wish.
well this is very general but hope it will help u.
in the servlet use
req.getWriter()-to write just like u do in html(req is an object of HttpServletRequest)
hope this will be adequate for u
consult java server programming -wrox publication
or
java servlet programming--o'reilly
for further knowledge
bye. )
23 years ago
well i'm not using any server but using servletrunner which is used to view how a sevlet works i don't have java web server.i'm stuck with this problem and not able to move ahead in my project.
well i'm new to servlet programming.
thanks anyway
23 years ago
servletrunner was running.whats servlet container
the servletrunner was showing init when the applet called the servlet
23 years ago

its sending a string and add hello to the string by the servlet and returned to the applet
//applet
import java.applet.*;
import java.awt.*;
import java.io.*;
import java.awt.event.*;
import java.net.*;
import java.util.*;
/*
<applet code="appservlet" width=100 height=100>
</applet>
*/
public class appservlet extends Applet{
TextField tf,tf1;
Button b1,b;
URLConnection uc;
public void init()
{
try {
tf=new TextField();
tf1=new TextField();
b=new Button("send");
b1=new Button("receive");
add(tf);
add(tf1);
add(b);
add(b1);
ButtonHandlerS bs=new ButtonHandlerS();
ButtonHandlerR br=new ButtonHandlerR();
b1.addActionListener(br);
b.addActionListener(bs);
}
catch(Exception ex)
{System.out.println(ex);}
}
void sendData()
{
try{
String queryString=tf.getText();
URL url=new URL("http://localhost:8080/servlet/srverapp");
uc=url.openConnection();
uc.setDoOutput(true);
uc.setDoInput(true);
uc.setUseCaches(false);
uc.setRequestProperty("Content-Type","application/x-www-form-urlencoded");
String qry=URLEncoder.encode("qrl")+"="+URLEncoder.encode(queryString);
DataOutputStream dos=new DataOutputStream(uc.getOutputStream());
dos.writeBytes(qry);
dos.flush();
dos.close();}
catch(Exception ex)
{System.out.println(ex);}
}
void getData()
{
try{
InputStreamReader in=new InputStreamReader(uc.getInputStream());
int chr=in.read();
while (chr!=-1)
{
tf1.setText(String.valueOf((char)chr));
chr=in.read();
}
in.close();}
catch(Exception ex)
{System.out.println(ex);}
}
class ButtonHandlerS implements ActionListener{
public void actionPerformed(ActionEvent ae)
{
sendData();
tf.setText("");
}
}
class ButtonHandlerR implements ActionListener{
public void actionPerformed(ActionEvent ae)
{
getData();

}
}
}
//servlet
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class srverapp extends HttpServlet{
public void doGet(HttpServletRequest req,HttpServletResponse res)
{

try
{

String str=req.getParameter("qry");
PrintWriter pw=res.getWriter();
pw.println("hello"+str);
pw.println("<html><head><title>trial</title></head>");
pw.println("<body>str</body>");
pw.println("</html>");
}
catch(IOException ie)
{
System.out.println(ie);
}
}
}
using serveletrunner
error:FileNotFoundException:http://localhost:8080/servlet/srveapp

thankyou
23 years ago
i'm trying to do applet servlet communication but it gives error
FileNotFoundException:http://localhost:8080/servlet/srverapp
i'm using servletrunner,can i do applets-ervelet communication using servletrunner.someone told me i'll have to use JWS for it.
thankyou
23 years ago
what's wrong in the code.i'm not able to put the result in a string object.

import java.sql.*;
class DataBaseConnect {
public static void main(String args[]) throws Exception
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String sourceURL=new String("jdbc dbc:db1");
Connection con=DriverManager.getConnection(sourceURL);
Statement statement=con.createStatement();
ResultSet rs=statement.executeQuery("select productdescription from products where productid>1");
String str=rs.getString("productdescription");
while (rs.next())
{
System.out.println(str);
}
}
}

thanks a lot.i'll keep it in mind.i'm highly grateful to you.thanks for taking the pain.
well sorry to say i've made the change still its not working.did u tried the code on machine.well it should be working still it isn't don't know where the problem lies.???
well sorry to say i've made the change still its not working.did u tried the code on machine.well it should be working still it isn't don't know where the problem lies.???

//server side
import java.io.*;
import java.net.*;
class clientsoc1{
public static void main(String args[]) throws Exception
{
InetAddress i=InetAddress.getLocalHost();
String str=new String();
String strt=new String();
Socket soc=new Socket(i,4444);
System.out.println(soc.getInetAddress());
BufferedReader is=new BufferedReader(new InputStreamReader(soc.getInputStream()));
DataOutputStream os=new DataOutputStream(soc.getOutputStream());
BufferedReader bs=new BufferedReader(new InputStreamReader(System.in));
str=bs.readLine();
int i1=str.length();
strt=is.readLine();
os.writeChars(str);
os.write(10);//change made
System.out.println(strt);
os.flush();
is.close();
os.close();
soc.close();
}
}
//client side
import java.net.*;
import java.io.*;
class Serversoc1{
public static void main(String args[]) throws Exception
{
String str1=new String();
ServerSocket scos=new ServerSocket(4444);
Socket soc1=scos.accept();
System.out.println(soc1);
BufferedReader br=new BufferedReader(new InputStreamReader(soc1.getInputStream()));
DataOutputStream ds=new DataOutputStream(soc1.getOutputStream());
System.out.println("on server now");
str1= br.readLine();//change done
System.out.println(str1);// prints on the server side
ds.writeChars(str1);
ds.write(10);//change done
ds.flush();
br.close();
ds.close();
soc1.close();
}
}
it is still not working.please try it out.i've been working on it for a long time.but still ,if the message is not send back to the client
then it works properly the message is printed on the server side.