aspose file tools*
The moose likes JSP and the fly likes would u like to open the file or save it to your system Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "would u like to open the file or save it to your system" Watch "would u like to open the file or save it to your system" New topic
Author

would u like to open the file or save it to your system

aman hindustani
Ranch Hand

Joined: Jun 15, 2006
Posts: 57
Hello friends,

I am writing a one jsp which consits of textfield,textarea,combobox etc..which is calling a servelt..as request ..is processing ...file download ..window is opening..why this is coming...i want to know..so that ..i can use it.in other case ...where i can save a file ...to my system..in attachment programme..please help me out..

Thanks Friends...


jsp



<html>

<head>
<title> This is a sample Programme </title>
</head>
<form name = "JustFormJsp" method="post" action="/venkat/servlet/JustFormServlet">
<body bgcolor="honeyDew">

<table align="center" >
<tr>
Name:<input type=text name="userName" value="">
</tr>
<tr>
Password:<input type=password name=password value="">
</tr>

<tr>
Sex: <input type=radio name="sex" value="Male" checked> Male
<input type=radio name="sex" value="Female"> Female
</tr>
<tr>
Age: <select name="age"><option>0-10<option>11-20<option>21-30<option>31-40<option>41-50
</tr>
<tr>
Education:<input type="checkbox" name="inter" value="Inter">Inter
<input type="checkbox" name="graduate" value="Graduate">Graduate
<input type="checkbox" name="postgraduate" value="PostGraduate">PostGraduate
</tr>
<tr>
Hobbies:<select name="hobbies" size="3" multiple>
<option>Swimming<option>Tennis<option>Hockey<option>Cricket<option>Chess<option>Kabadi<option>Table Tennis
</tr>
<tr>
Extra Activities: <textArea name="extras" rows="10" cols="50" bgcolor="cyan"></textarea>
</tr>


<tr align="center" >
<input type="submit" name="submit" value="Submit">
<input type="reset" name="refresh" value="Refresh">
</tr>
</table>

</body>
</form>
</html>




Servlet




import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;

public class JustFormServlet extends HttpServlet
{


public void service( HttpServletRequest request,HttpServletResponse response) throws IOException, ServletException
{
response.setContentType("html/text");
PrintWriter pw = response.getWriter();

String name = request.getParameter("userName");
String password = request.getParameter("password");
String sex = request.getParameter("sex");
String age = request.getParameter("age");
String inter = request.getParameter("inter");
String graduate = request.getParameter("graduate");
String postgraduate = request.getParameter("postgraduate");
String hobies = request.getParameter("hobbies");
String area = request.getParameter("extras");

String[] hobbies = request.getParameterValues("hobbies");

int serverport = request.getServerPort( );
//int localport = request.getLocalPort();

pw.println("ur name is "+name+" and ur pass word is "+password+" and ur "+sex+" ur education is "+inter+" "+graduate +" "+postgraduate+" and ur age is between "+age+" and about u " + area);

//System.out.println("ur server port number is "+serverport);
System.out.println("ur hobbies are ");
for(int i=0; i <(hobbies.length);i++){
System.out.println(hobbies[i]);
}


}
}
Richard Green
Ranch Hand

Joined: Aug 25, 2005
Posts: 536
response.setContentType("html/text");

should be response.setContentType("text/html");


MCSD, SCJP, SCWCD, SCBCD, SCJD (in progress - URLybird 1.2.1)
aman hindustani
Ranch Hand

Joined: Jun 15, 2006
Posts: 57
Thank Q very much...
aman hindustani
Ranch Hand

Joined: Jun 15, 2006
Posts: 57
Hello MR.LYNETTE DAWSON...Thanks for ur reply ...please help me in this case also..Thanks in Advance


One more doubt ..i am wrinting a code..for just view an image ..as

response.setContentType("image/jpeg");

it is working well...but i want not only just to view..but also want an option to save ..to the system..in order to get it..what should i do..

i tried with response.setContentType("html/image");
and also with response.setContentType("html/image/jpeg");

it should showing download wizard...but saving some jsp page...with some data ..which is not understandable....please help me out...what should i do..
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: would u like to open the file or save it to your system