Baka Neko

Greenhorn
+ Follow
since Dec 09, 2003
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 Baka Neko

Hooray

Its working now for me..many thx!!!

Greetz

Pascal
19 years ago
Hey all

I could need a little help with my stuff thats going on here. I cant figure out, why i cant send 2 parameters from my javascript to one servlet and on the other hand its working for another servlet everything from ONE and the SAME jsp..here is the jsp:



This jsp is reading all the files out of a bean and shows em in one table. Its part of a Fileupload / Download + MySQL..some sort of Documentmanagementsystem. The setCMD2 function is working...there you can see, that i got 3 parameters. But the setCMD isnt working..its only working for the filename..if it try to send the fileextension as a paramter to the _Download Servlet..everything crashes...

Any help would be really cool


TIA

Pascal


P.S.: Had to rename o n Click() to on_Click()..board said so
19 years ago
Thx for your reply..
Im working on a project (document management) that let users download certain files from a server. The user can modify these files, or simply download an do whatever he / she wants with em. If the files have been modified I wanna do an automatically upload of the modified file. Thats y I have to force the user to download the file to a specific folder.
Baka out
20 years ago
Howdy
Like mentioned above..I want to force the download of a file to a specific folder. I need to do that, for doing an automatically upload for modified dowloaded files...
Any ideas how I could solve this prob ?
TIA
Baka out
20 years ago
Screw jspSmartUpload for downloading Ive wrote my own DownloadServlet..if anyone is interested. Here it is:
package dasProjekt;
import java.io.IOException;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
/**
* @author ooGAUoo
*
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
public class DasDownloadServlet extends HttpServlet {

private ServletConfig servletConfig;
private ServletContext servletContext;
public void init(ServletConfig config) throws ServletException {

super.init(config);
servletConfig = config;
servletContext = servletConfig.getServletContext();
//TODO Method stub generated by Lomboz
}


public void doGet(HttpServletRequest req,HttpServletResponse res) throws ServletException, IOException {

ServletOutputStream out = res.getOutputStream();
String filename = req.getParameter("fn");
// kein file, also auch nix zum downen
if (filename == null) {

System.out.println("File nicht vorhanden");
return;
}
String pathName = "D:/upload2/" +filename;
//String pathName = getServletContext().getRealPath("/" + filename);
String contentType = getServletContext().getMimeType(pathName);

//if (contentType != null) res.setContentType(contentType);
//else
res.setContentType("application/x-msdownload");
res.setHeader ("Content-Disposition", "attachment; filename=\"" + filename + "\"");
// Return the file
try {
returnFile(pathName, out);
}
catch (FileNotFoundException e) {
System.out.println("Kein File gefunden: " + pathName);
}
catch (IOException e) {
System.out.println("Error beim Senden " + pathName + ": " + e.getMessage());
}
}



//TODO Method stub generated by Lomboz


public static void returnFile(String filename, OutputStream out) throws FileNotFoundException, IOException {

FileInputStream fis = null;
try {
fis = new FileInputStream(filename);
byte[] buf = new byte[4 * 1024]; // 4K buffer damit er auch kleinere files schluckt..
int bytesRead;
while ((bytesRead = fis.read(buf)) != -1)
out.write(buf, 0, bytesRead);
}
finally {
if (fis != null) fis.close();
}
}
}

Enjoy and its working real good
Baka out
20 years ago
Hey everybody
Like mentioned above..Im using jspSmartUpload to upload files via jsp to a local path at my HD. Im also using this class for downloading. Everything is working great BUT i am not able to download files smaller than 8k This is driving me crazy, cause downloading other bigger files is working like a charm.
This is what Im getting for downloading files <8k:
java.lang.IllegalStateException: getOutputStream() has already been called for this response
at org.apache.coyote.tomcat4.CoyoteResponse.getWriter(CoyoteResponse.java:614)
at org.apache.coyote.tomcat4.CoyoteResponseFacade.getWriter(CoyoteResponseFacade.java:173)
at org.apache.jasper.runtime.JspWriterImpl.initOut(JspWriterImpl.java:173)
at org.apache.jasper.runtime.JspWriterImpl.flushBuffer(JspWriterImpl.java:166)
at org.apache.jasper.runtime.PageContextImpl.release(PageContextImpl.java:184)
at org.apache.jasper.runtime.JspFactoryImpl.internalReleasePageContext(JspFactoryImpl.java:198)
at org.apache.jasper.runtime.JspFactoryImpl.releasePageContext(JspFactoryImpl.java:193)
at org.apache.jsp.geoeffnet_jsp._jspService(geoeffnet_jsp.java:51)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:137)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:210)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:684)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:432)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:356)
at dasProjekt.NeueVerbindung.service(NeueVerbindung.java:206)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:684)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:432)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:356)
at org.apache.jasper.runtime.PageContextImpl.forward(PageContextImpl.java:430)
at org.apache.jsp.oeffnen_jsp._jspService(oeffnen_jsp.java:79)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:137)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:210)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2416)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:171)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:223)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:601)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:392)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:565)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:619)
at java.lang.Thread.run(Thread.java:534)

Hopefully someone in here got a great idea, how to solve this annoying problem.
TIA
BakaNeko
[ January 04, 2004: Message edited by: Baka Neko ]
[ January 04, 2004: Message edited by: Baka Neko ]
20 years ago
Ahaahaha Ive solved it...jeez.stupid me.
HttpSession mysession = request.getSession(true);
mysession.setAttribute("einFile", dasFile);
Inserted this into my Servlet..and now its working like a charm
Many thx for helping out.
Baka out
20 years ago
JSP
Thx for your Reply
Ive lowercased all the Strings in my Bean..and if Im doing <jsp:getProperty..> now Im also getting Null and no Jasper Error anymore.
Soo..I guess its like you�ve already said..there is no filled bean inside my session....
Have to get this bean into my session and have to read a little more about Beans
Baka out
20 years ago
JSP
Howdy
Ok..here it goes my little Prob:
Im currently working on uploading a File via Smartupload. Upload is working as a Servlet. But i also wanna store the Filenames / Extensions and an ID to a MySQL Database. Therefore i need these Strings to store em.
Im getting these Strings in my UploadServlet and Im sending em to my Files-Bean.
Code of the Bean:
package dasProjekt;
public class DieFiles {

private String ID;
private String Filename;
private String Extension;


public DieFiles(){
}

public String getID(){

System.out.println("in getID");

return ID;
}
public void setID(String ID){
System.out.println("in setID");

this.ID = ID;
}
public String getFilename(){
System.out.println("in getFilename");

return Filename;
}
public void setFilename(String Filename){

System.out.println("in setFilenam");

this.Filename = Filename;
}
public String getExtension(){
System.out.println("in getExtension");

return Extension;
}
public void setExtension(String Extension){

System.out.println("in setExtension");
this.Extension = Extension;
}
}
Nothing special. Ive tested the Bean with the System.out.println(...) and everything is ok with my Bean.
BUT If I wanna see the Filename, ID, Extension in my JSP via by calling the method itself <%= DieFiles.getFilename()%>
Im getting:
NULL
And if Im trying <jsp:getProperty ...> Im getting:
org.apache.jasper.JasperException: Cannot find any information on property 'Filename' in a bean of type 'dasProjekt.DieFiles'

But like Ive said, if Im doing a System.out.Println(einFile.getFilename());
in the Servlet its working fine.
Heres the code from my JSP:
<%@ page language="java" %>
<jsp:useBean id="einFile" class="dasProjekt.DieFiles" scope="session"/>
</jsp:useBean>
<HTML>
<BODY BGCOLOR="white">
Upload komplett!
Hier muss halt auch ne DB Connection entstehen in der die TaskID, Filename zur DB geuppt werden.
Alles l�uft �ber meine DieConnection Bean ab!

Filename: <%= einFile.getFilename()%>
Filename: <jsp:getProperty name="einFile" property="Filename"/>
<meta http-equiv="refresh" content="5; url='UploadedFiles.jsp'">

</BODY>
</HTML>

Any help and suggestions would be awesome
TIA
Baka out
20 years ago
JSP
public void contextInitialialized(ServletContextEvent sce)
{
String tag = sce.getServletContext().getInitParameter("Name of the Parameter you wannna have the value, in your case path");
System.out.println(tag);
}
Im also in the middle of this problem. Lol
Maybe this will help ya...for me Im still getting NULL ...maybe there is something wrong with the invoker of the web.xml in Tomcat-Folder..o_O?
Any help would be great!
Baka out
20 years ago
^^
I�ve just solved my prob..not the way I would like it in the first place, but its working now.
a new JSP called hello1.jsp:
<%@ page language="java" %>
<!DOCTYPE HTML PUBLIC "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
<title>Lomboz JSP</title>
</head>
<body bgcolor="#FFFFFF">
<form method="post" name="test" action="HelloWorldServlet" >
<input type="text" name="test" Value="test" size="10">
<input type="submit" value="Dr�ck Mich" >
</form>
</body>
</html>
new enhanced Servlet
public class HelloWorldServlet extends HttpServlet {

private ServletConfig servletConfig;
private ServletContext servletContext;

public void init(ServletConfig config) throws ServletException {
super.init(config);
servletConfig = config;
servletContext = servletConfig.getServletContext();


}

public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
System.out.println("bin in doGet");
doPost(req, res);
}
public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {

System.out.println("jetzt in doPost");
String test;
test = req.getParameter("test");
System.out.println(test);
String target ="/hello.jsp";
req.setAttribute("message", test);
RequestDispatcher rd;
rd = getServletContext().getRequestDispatcher(target);
rd.forward(req,res);

}
}
I can send any String to the Servlet now and it�ll show up in the hello.jsp.
Even better than a simple "HelloWorld"

Many thx for your suggestions and help.
Baka out
20 years ago
Thx for your reply
Im not sure, what�s the easiest way, but atm. I only got 1 JSP that is calling the servlet and is recieving the String.
Baka out
20 years ago
Hey all
I�m kinda new to all this Servlet / JSP Stuff and I�m even not quite sure, if this belongs in the right forum, but I hope someone in here can help me out.
I got this simple HelloWorld-Based Jsp/Servlet Prob. The JSP should "call" the servlet, the servlet should generate a simple message and send it to the JSP.
Heres my code:
Servlet:
package = mein.packetchen.ui.toll;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.lang.*;

public class HelloWorldServlet extends HttpServlet {

private ServletConfig config;

public void init(ServletConfig config) throws ServletException {
this.config = config;
this.init();
}

public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
System.out.println("bin in doGet");
doPost(req, res);
}
public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {

System.out.println("jetzt in doPost");
String theMessage ="Hi!";
String target ="/hello.jsp";
req.setAttribute("message", theMessage);
RequestDispatcher rd;
rd = getServletContext().getRequestDispatcher(target);
rd.forward(req,res);
}
}

JSP:
<%@ page language="java" %>
<%@ page import="java.lang.*" %>
<%@ page import="mein.packetchen.ui.toll.*%>
<%String msg = (String)request.getAttribute("message"); %>
<html>
<body>
<%System.out.println(msg);%>
<%= msg %>
</body>
</hmtl>
Everytime Im calling the JSP Im getting back NULL for the String.

Any help will be appreciating
TIA
Baka out
20 years ago
Hey..maybe i can help ya out
I guess your fileupload page looks similiar to this one
<FORM METHOD="POST" ACTION="files.jsp" ENCTYPE="multipart/form-data">
<INPUT TYPE="FILES" NAME="FILES" SIZE="50"><BR>
<INPUT TYPE="SUBMIT" VALUE="Upload">
</FORM>
It then links to the "files.jsp" where all my uploaded files are validated.
If you got also a jsp file doing that for you, you can simply do something like this to show the messages you wanna show:
%>
<h1>Upload done!</h1>
<meta http-equiv="refresh" content="5; url='yournextpagehere.jsp'">
<%
You�ll get redirected to your next jsp page automatically.
Hope this will help you a little bit.
Cheers
Baka out
20 years ago
JSP