derick nial

Greenhorn
+ Follow
since Sep 26, 2013
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
1
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by derick nial

hi. i am working on android platform. how to do search function with expandable List? specifically i have problem with my adapter.
9 years ago
i have this layout consist of tables, text boxes, radio buttons,combo boxes and button. i also have the "file" button in my UI(i already use 'enctype=multipart/form-data')
before this i was trying to update a file and it works.

i know that by getting the fieldName() and value will get me the values for textboxes,radiobutton etc.. what i dont know is on how to retrieve ALL the fieldName(),values TOGETHER with my previous layout by using above method??? i know i need to do something on the if (item.isFormField()), im just not sure how.
i

You don't tell us where your image is located.


the image is in here----> C:\Users\Acer\Desktop\mine\images\Extra\sunset.jpg

In your previous topic, I told you that you needed to package the image with your web application.


how to do this?
10 years ago
This is in my jsp

This is in my servlet:

My question is, how to make this dynamic?
i mean i don't want to write hardcoded of the address path.

i have tried


i also have tried

but the address returned was:


what i really want is:


I would greatly appreciate it if you kindly give me some feedback. thanks.
10 years ago
Thanks for your respond Joe;

Joe Ess wrote:If you want to locate an image (or some other file), the best practice is to package it in your application and use Class.getResource() to locate it.


do you have any example on how this is to be done?

Joe Ess wrote: don't forget the security precautions that I specified earlier.


yes thank you Joe, i already made file's size and file's type validation as you advised earlier. (:
10 years ago
thank you for your reply,


i have tried using above method on getting the path, but what i was getting:

what i really want(the location of the image):

what other method should i use? tq.
10 years ago

is there any way i can make this source search as dynamic search? i mean i don't want to set the static folder.

thanks in advance
10 years ago
Yes. The <input> is basically for the frame where i want the image to be displayed at. And no, there are no other servlet. Just one.
10 years ago

im trying to display image and other contents in jsp page, however i keep on getting the image alone.and i dont know why

here is the code from my servlet:


and here is from my jsp:


please help me on this, hope to receive reply from you all ASAP.

thanks in advance (:
10 years ago
so sorry for that, it just that my dateline is in next few days time. anw here is from my servlet:

public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
// Parse URI to find the filename
String uri = request.getRequestURI();
String[] tokens = uri.split("/");
String filename = "";

for(int i = 2; i < tokens.length; i++){
filename += ("/" + tokens[i]);
}

// Set Content type
String contentType = getServletContext().getMimeType(filename);

// Stream the image
BufferedInputStream in = null;
try
{
in = new BufferedInputStream(getServletContext().getResourceAsStream("/WEB-INF/" + filename));

response.setContentType(contentType);
response.setHeader("Content-Disposition", " inline; filename=" + filename);

ServletOutputStream out = response.getOutputStream();

byte[] buffer = new byte[4 * 1024];

int data;
while((data = in.read(buffer)) != -1)
{
out.write(buffer, 0, data);
}
out.flush();
}
catch(Exception e)
{
e.printStackTrace();
return;
}
finally
{
try
{
in.close();
}
catch(Exception ee)
{
ee.printStackTrace();
}
}
}

and this is my jsp:

<%
byte[] imgData = profile.getAvatar();
response.setContentType("text/html");

try{
if (profile.getAvatar()!= null) {

String fileName = request.getParameter("imagepath");
response.setContentType("image/png");
BufferedOutputStream o = new BufferedOutputStream(response.getOutputStream());
o.write(imgData);
System.out.println("fileName----->"+fileName);
%>
<input type="image" name="avatar" id="avatar" >

<% }else{
if (profile.getAvatar() == null){
// %>
<input type="image" name="avatar" id="avatar"src="img/no_avatar.png" /> }
<% }
}
} catch(IOException e){

}finally{
// close the streams
}
%>

can you tell me what went wrong? :/
10 years ago
and also in the previous example, the images are stored in a folder,but mine i wanna try to retrieve it from the database, not the folder, so if you could please help to tell me how to write the right img src address for this kind of problem. tq
10 years ago
i already tried to add the doGet method in my servlet, the thing is now im not quite sure how to implement/call/link this doGet method with my codes in jsp. please help. tq
10 years ago
hi,

how can i identify/ allocate the url address for the img src ? the image is from the database. hope to get reply soon, thanks.
10 years ago
hi Bear Bibeault, i already studied and tried to implement the method from the example you shared,and yet it still not working, do you have any other ways? please
10 years ago
Thank you for your fast respond. Do you have any example/ links on how might this servlet look like?
10 years ago