Search Results

Search found 696 results on 28 pages for 'servlets'.

Page 12/28 | < Previous Page | 8 9 10 11 12 13 14 15 16 17 18 19  | Next Page >

  • How a servlet can get the absolute path to a file outside of the servlet?

    - by WolfmanDragon
    We have been using System.getProperties("user.dir") to get the location of a properties file. Now that it has been deployed on Tomcat(via servlet), the System call is giving the location as tomcat and not at the location at where the properties file exist. How can we call the the properties file dynamically? Given: Tomcat is not the only way the app will be deployed We have no control on where the app may be placed. Relative paths will not work as that Vista is being used and Vista breaks relative paths. This must work on all OS, including(but not limited to) Linux, XP and Vista. EDIT I implied this, but in case I was not clear enough, I have no way of knowing the path String.

    Read the article

  • web.xml : URL mapping

    - by Devashish Dixit
    I have these two lines in my web.xml <url-pattern>/</url-pattern> : Index Servletand <url-pattern>/login</url-pattern> : Login Servlet but whem I open http://localhost:8084/login/, it goes to Index Servlet and when I open http://localhost:8084/login, it goes to Login Servlet. Is there any difference in http://localhost:8084/login/ and http://localhost:8084/login? My web.xml <servlet> <servlet-name>Index</servlet-name> <servlet-class>Index</servlet-class> </servlet> <servlet> <servlet-name>Login</servlet-name> <servlet-class>Login</servlet-class> </servlet> and <servlet-mapping> <servlet-name>Index</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>Login</servlet-name> <url-pattern>/login</url-pattern> </servlet-mapping>

    Read the article

  • on Google App Engine 500 Error, it should be 200 instead of 500

    - by Faisal Amjad
    requestToken = function() { var getTokenURI = '/gettoken?userid=' + userid; var httpRequest = makeRequest(getTokenURI, true); httpRequest.onreadystatechange = function() { if (httpRequest.readyState == 4) { if (httpRequest.status == 200) { openChannel(httpRequest.responseText); } else { alert('ERROR: AJAX request status = ' + httpRequest.status); } } } }; function makeRequest(url, async) { var httpRequest; if (window.XMLHttpRequest) { httpRequest = new XMLHttpRequest(); } else if (window.ActiveXObject) { // IE try { httpRequest = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { httpRequest = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) { } } } if (!httpRequest) { return false; } httpRequest.open('POST', url, async); httpRequest.send(); return httpRequest; } it is running excellent on localhost...but on google app engine it httpRequest.status equals 500 and goes in else statement. WHY? LOG on google app engine: /getFriendList?userid=d 500 253ms 0kb Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.97 Safari/537.11 175.110.179.86 - - [17/Dec/2012:08:35:33 -0800] "POST /getFriendList?userid=d HTTP/1.1" 500 0 "http://faisalimmsngr.appspot.com/" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.97 Safari/537.11" "faisalimmsngr.appspot.com" ms=254 cpu_ms=110 instance=00c61b117caf2d11ca57d2a2296ccd0b902b038a W 2012-12-17 08:35:33.272 Failed startup of context com.google.apphosting.utils.jetty.RuntimeAppEngineWebAppContext@10ff62a{/,/base/data/home/apps/s~faisalimmsngr/1.363934467542140431} org.mortbay.util.MultiException[java.lang.UnsupportedClassVersionError: adv/web/mid/exam/FriendServlet : Unsupported major.minor version 51.0, java.lang.UnsupportedClassVersionError: adv/web/mid/exam/MessageServlet : Unsupported major.minor version 51.0, java.lang.UnsupportedClassVersionError: adv/web/mid/exam/TokenServlet : Unsupported major.minor version 51.0] at org.mortbay.jetty.servlet.ServletHandler.initialize(ServletHandler.java:656) at org.mortbay.jetty.servlet.Context.startContext(Context.java:140) at org.mortbay.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1250) at org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:517) at org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:467) at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50) at com.google.apphosting.runtime.jetty.AppVersionHandlerMap.createHandler(AppVersionHandlerMap.java:219) at com.google.apphosting.runtime.jetty.AppVersionHandlerMap.getHandler(AppVersionHandlerMap.java:194) at com.google.apphosting.runtime.jetty.JettyServletEngineAdapter.serviceRequest(JettyServletEngineAdapter.java:134) at com.google.apphosting.runtime.JavaRuntime$RequestRunnable.run(JavaRuntime.java:447) at com.google.tracing.TraceContext$TraceContextRunnable.runInContext(TraceContext.java:454) at com.google.tracing.TraceContext$TraceContextRunnable$1.run(TraceContext.java:461) at com.google.tracing.TraceContext.runInContext(TraceContext.java:703) at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContextNoUnref(TraceContext.java:338) at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContext(TraceContext.java:330) at com.google.tracing.TraceContext$TraceContextRunnable.run(TraceContext.java:458) at com.google.apphosting.runtime.ThreadGroupPool$PoolEntry.run(ThreadGroupPool.java:251) at java.lang.Thread.run(Thread.java:679) java.lang.UnsupportedClassVersionError: adv/web/mid/exam/FriendServlet : Unsupported major.minor version 51.0 at com.google.appengine.runtime.Request.process-c04431eac3a1f275(Request.java) at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClass(ClassLoader.java:634) at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142) at java.net.URLClassLoader.defineClass(URLClassLoader.java:277) at sun.reflect.GeneratedMethodAccessor5.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:616) at java.lang.ClassLoader.loadClass(ClassLoader.java:266) at org.mortbay.util.Loader.loadClass(Loader.java:91) at org.mortbay.util.Loader.loadClass(Loader.java:71) at org.mortbay.jetty.servlet.Holder.doStart(Holder.java:73) at org.mortbay.jetty.servlet.ServletHolder.doStart(ServletHolder.java:242) at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50) at org.mortbay.jetty.servlet.ServletHandler.initialize(ServletHandler.java:685) at org.mortbay.jetty.servlet.Context.startContext(Context.java:140) at org.mortbay.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1250) at org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:517) at org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:467) at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50) at com.google.tracing.TraceContext$TraceContextRunnable.runInContext(TraceContext.java:454) at com.google.tracing.TraceContext$TraceContextRunnable$1.run(TraceContext.java:461) at com.google.tracing.TraceContext.runInContext(TraceContext.java:703) at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContextNoUnref(TraceContext.java:338) at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContext(TraceContext.java:330) at com.google.tracing.TraceContext$TraceContextRunnable.run(TraceContext.java:458) at java.lang.Thread.run(Thread.java:679)

    Read the article

  • How to add response headers based on Content-type, or getting Content-type before the response is co

    - by Bozho
    I want to set the Expires header for all image/* and text/css. I'm doing this in a Filter. However: before calling chain.doFilter(..) the Content-type is not yet "realized" after calling chain.doFilter(..) the Content-type is set, but so is content-length, which forbids adding new headers (at least in Tomcat implementation) I can use the extensions of the requested resource, but since some of the css files are generated by richfaces by taking them from inside jar-files, the name of the file isn't x.css, but is /xx/yy/zz.xcss/DATB/.... So, is there a way to get the Content-type before the response is committed.

    Read the article

  • How do I correctly decode unicode parameters passed to a servlet

    - by Grant Wagner
    Suppose I have: <a href="http://www.yahoo.com/" target="_yahoo" title="Yahoo!&#8482;" onclick="return gateway(this);">Yahoo!</a> <script type="text/javascript"> function gateway(lnk) { window.open(SERVLET + '?external_link=' + encodeURIComponent(lnk.href) + '&external_target=' + encodeURIComponent(lnk.target) + '&external_title=' + encodeURIComponent(lnk.title)); return false; } </script> I have confirmed external_title gets encoded as Yahoo!%E2%84%A2 and passed to SERVLET. If in SERVLET I do: Writer writer = response.getWriter(); writer.write(request.getParameter("external_title")); I get Yahoo!â„¢ in the browser. If I manually switch the browser character encoding to UTF-8, it changes to Yahoo!TM (which is what I want). So I figured the encoding I was sending to the browser was wrong (it was Content-type: text/html; charset=ISO-8859-1). I changed SERVLET to: response.setContentType("text/html; charset=utf-8"); Writer writer = response.getWriter(); writer.write(request.getParameter("external_title")); Now the browser character encoding is UTF-8, but it outputs Yahoo!â?¢ and I can't get the browser to render the correct character at all. My question is: is there some combination of Content-type and/or new String(request.getParameter("external_title").getBytes(), "UTF-8"); and/or something else that will result in Yahoo!TM appearing in the SERVLET output?

    Read the article

  • Second level cache for java web app and its alternatives

    - by EugeneP
    Between the transitions of the web app I use a Session object to save my objects in. I've heard there's a program called memcached but there's no compiled version of it on the site, besides some people think there are real disadvantages of it. Now I wanna ask you. What are alternatives, pros and cons of different approaches? Is memcached painpul for sysadmins to install? Is it difficult to embed it to the existing infrastructure from the perspective of a sysadmin? What about using a database to hold temporary data between web app transitions? Is it a normal practice?

    Read the article

  • How to convert MS doc to pdf

    - by magh
    How to convert doc to pdf using java api. where document contains various formats such as tables in ms word. when converting to pdf using iText. where actual document looks different to converted pdf. please provide any api not an exe installed for converting . must be an open source

    Read the article

  • Detecting client disconnect in tomcat servlet?

    - by Seth
    How can I detect that the client side of a tomcat servlet request has disconnected? I've read that I should do a response.getOutputStream().print(), then a response.getOutputStream().flush() and catch an IOException, but is there a way I can detect this without writing any data?

    Read the article

  • Download dynamic file with GWT

    - by Maksim
    I have a GWT page where user enter data (start date, end date, etc.), then this data goes to the server via RPC call. On the server I want to generate Excel report with POI and let user save that file on their local machine. This is my test code to stream file back to the client but for some reason I think it does not know how to stream file to the client when I'm using RPC: public class ReportsServiceImpl extends RemoteServiceServlet implements ReportsService { public String myMethod(String s) { File f = new File("/excelTestFile.xls"); String filename = f.getName(); int length = 0; try { HttpServletResponse resp = getThreadLocalResponse(); ServletOutputStream op = resp.getOutputStream(); ServletContext context = getServletConfig().getServletContext(); resp.setContentType("application/octet-stream"); resp.setContentLength((int) f.length()); resp.setHeader("Content-Disposition", "attachment; filename*=\"utf-8''" + filename + ""); byte[] bbuf = new byte[1024]; DataInputStream in = new DataInputStream(new FileInputStream(f)); while ((in != null) && ((length = in.read(bbuf)) != -1)) { op.write(bbuf, 0, length); } in.close(); op.flush(); op.close(); } catch (Exception ex) { ex.printStackTrace(); } return "Server says: " + filename; } } I've red somewhere on internet that you can't do file stream with RPC and I have to use Servlet for that. Is there any example of how to use Servlet and how to call that servlet from ReportsServiceImpl. Do I really need to make a servlet or it is possible to stream it back with my RPC?

    Read the article

  • How do I stop Safari from caching my Servlet response?

    - by Cliff
    I'm having trouble testing a web app with Safari. My app returns wave audio data. The problem happens when I change the application and hit it again from Safari. Safari caches the original response so no matter how many times I hit refresh it seems like I've not updated anything. I can almost get around this using force refresh with Firefox but because I'm having trouble generating the wave headers using the javax.sound API Firefox only plays the first second of audio returned. A few weeks ago I tried setting the HTTP header in my servlet to prevent caching but I don't think I was setting it correctly. (What is the header for browser cache control?) This is becoming a real pain and I'm looking for any ideas, comments, or alternative approaches. I'm getting ready to try again but I figured I'd ask here in the interim to see if someone can provide help.

    Read the article

  • java servlet:response.sendRedirect() not giving illegal state exception if called after commit of re

    - by sahil garg
    after commit of response as here redirect statement should give exception but it is not doing so if this redirect statemnet is in if block.but it does give exception in case it is out of if block.i have shown same statement(with marked stars ) at two places below.can u please tell me reason for it. protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub synchronized (noOfRequests) { noOfRequests++; } PrintWriter pw=null; response.setContentType("text/html"); response.setHeader("foo","bar"); //response is commited because of above statement pw=response.getWriter(); pw.print("hello : "+noOfRequests); //if i remove below statement this same statement is present in if block.so statement in if block should also give exception as this one do, but its not doing so.why? ***response.sendRedirect("http://localhost:8625/ServletPrc/login% 20page.html"); if(true) { //same statement as above ***response.sendRedirect("http://localhost:8625/ServletPrc/login%20page.html"); } else{ request.setAttribute("noOfReq", noOfRequests); request.setAttribute("name", new Name().getName()); request.setAttribute("GmailId",this.getServletConfig().getInitParameter("GmailId") ); request.setAttribute("YahooId",this.getServletConfig().getInitParameter("YahooId") ); RequestDispatcher view1=request.getRequestDispatcher("HomePage.jsp"); view1.forward(request, response); } }

    Read the article

  • Redirecting the response from a filter throws an IllegalStateException

    - by Ritesh M Nayak
    I am writing a filter that will handle all authentication related tasks. My filter is a standard servlet filter as shown below @Override public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException { UserSession attribute = (UserSession)request.getSession().getAttribute("user_session_key"); if(attribute!=null && attribute.isValid()) { //proceed as usual, chain.doFilter(req, res); return; } else { //means the user is not authenticated, so we must redirect him/her to the login page ((HttpServletResponse)res).sendRedirect("loginpage"); return; } } But when I do this, I get an IllegalStateException thrown by Tomcat's ResponseFacade. How do I acheive this in a filter. I read in other SO threads that in TOmcat this is a problem as the response object is already commited. How do I get past this ?

    Read the article

  • Where's javax.servlet?

    - by egaga
    I have jdk1.6.0_13 installed, but when I try to find a javax.servlet package, or press ctrl+space in Eclipse after Servlet I cannot get anything. Where can I download this package, and why isn't it included in standard distribution for developers?

    Read the article

  • Can't instantiate javax.servlet.ServletException

    - by Denis
    Hello, experts! I am trying to create instance of class javax.servlet.ServletException with following code public class MyTroubleViewer { public static void main(String[] args) { javax.servlet.ServletException servletException = new javax.servlet.ServletException("Hello"); System.out.println(servletException.getMessage()); } } But I get exception on creating: Exception in thread "main" java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/servlet/ServletException ... Maven helps me with dependecies: <dependency> <groupId>javax</groupId> <artifactId>javaee-api</artifactId> <version>6.0</version> <type>jar</type> <scope>compile</scope> </dependency> What am I doing wrong?

    Read the article

  • Sending BLOBs in a JSON service,... how?

    - by Marten Sytema
    Hello I have a webservice (ie. servlet) implemented in Java. It gets some data from a MySQL table, with one column being of type BLOB (an image), and some other columns are just plain text. Normally I would store the file outside the database with a pointer to it in the database, but due to circumstance I now have to use this BLOB column... What is the proper way to send this? How to encode the image in a JSONObject, and how to parse (and RENDER!) it on the otherside ? I want to use JSONP, to avoid having to proxy it through the consumer's webserver. So that the consumer can just put in a tag pointing to the webservice, calling a callback. Any thoughts how to handle images in this situation? Also thoughts on performance etc. are interesting!

    Read the article

  • Read media stream from servlet in a webpage?

    - by khue
    Hi, I have a servlet that construct response to a media file request by reading the file from server: File uploadFile = new File("C:\TEMP\movie.mov"); FileInputStream in = new FileInputStream(uploadFile); Then write that stream to the response stream. My question is how do I play the media file in the webpage using or tag to read the media stream from the response. Thank you very much. Regards K.

    Read the article

  • Maven dependency for Servlet 3.0 API?

    - by deamon
    How can I tell Maven 2 to load the Servlet 3.0 API? I tried: <dependency> <groupId>javax.servlet</groupId> <artifactId>servlet-api</artifactId> <version>3.0</version> <scope>provided</scope> </dependency> I use http://repository.jboss.com/maven2/ but what repository would be correct? Addendum: It works with a dependency for the entire Java EE 6 API and the following settings: <repository> <id>java.net</id> <url>http://download.java.net/maven/2</url> </repository> <dependency> <groupId>javax</groupId> <artifactId>javaee-api</artifactId> <version>6.0</version> <scope>provided</scope> </dependency> I'd prefer to only add the Servlet API as dependency, but "Brabster" may be right that separate dependencies have been replaced by Java EE 6 Profiles. Is there a source that confirms this assumption?

    Read the article

  • Getting parameter sent via html form and saving in my db

    - by Wesley
    I have error in my code i don't know to solve it please help me: My Servlet: package br.com.cad.servlet; import java.io.IOException; import java.io.PrintWriter; import java.util.Date; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import br.com.cad.dao.Cadastro; import br.com.cad.basica.Contato; public class AddDados extends HttpServlet{ protected void service(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { PrintWriter out = response.getWriter(); String nome = request.getParameter("nome"); String sobrenome = request.getParameter("sobrenome"); String rg = request.getParameter("rg"); String cpf = request.getParameter("cpf"); String sexo = request.getParameter("sexo"); StringBuilder finalDate = new StringBuilder("DataNascimento1") .append("/"+request.getParameter("DataNascimento??2")) .append("/"+request.getParameter("DataNascimento3")); try { SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy"); finalDate.toString(); } catch(ParseException e) { out.println("Erro de conversão da data"); return; } Contato contato = new Contato(); contato.setNome(nome); contato.setSobrenome(sobrenome); contato.setRg(rg); contato.setCpf(cpf); contato.setSexo(sexo); if ("Masculino".equals(contato.getSexo())) { contato.setSexo("M"); } else { contato.setSexo("F"); } contato.setDataNascimento1(dataNascimento1); //error here ????? contato.setDataNascimento2(dataNascimento2); //error here ????? contato.setDataNascimento3(dataNascimento3); //error here ????? Cadastro dao = new Cadastro(); dao.adiciona(contato); out.println("<html>"); out.println("<body>"); out.println("Contato " + contato.getNome() + " adicionado com sucesso"); out.println("</body>"); out.println("</html>"); } } My object dao package br.com.cad.dao; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.SQLException; import java.sql.Date; import br.com.cad.dao.ConnectDb; import br.com.cad.basica.Contato; public class Cadastro { private Connection connection; public Cadastro() { this.connection = new ConnectDb().getConnection(); } public void adiciona(Contato contato) { String sql = "INSERT INTO dados_cadastro(pf_nome, pf_ultimonome, pf_rg, pf_cpf, pf_sexo,pf_dt_nasc) VALUES(?,?,?,?,?,?,?,?)"; try { PreparedStatement stmt = connection.prepareStatement(sql); stmt.setString(1, contato.getNome()); stmt.setString(2, contato.getSobrenome()); stmt.setString(3, contato.getRg()); stmt.setString(4, contato.getCpf()); stmt.setString(5, contato.getSexo()); stmt.setDate(6, new Date( contato.getDataNascimento1().getTimeInMillis()) ); // i think there are error here i don't know to solve it ????? stmt.execute(); stmt.close(); System.out.println("Cadastro realizado com sucesso!."); } catch(SQLException sqlException) { throw new RuntimeException(sqlException); } } } My class cadastro package br.com.cad.basica; import java.util.Calendar; public class Contato { private Long id; private String nome; private String sobrenome; private String email; private String endereco; private Calendar dataNascimento1; private Calendar dataNascimento2; private Calendar dataNascimento3; private String rg; private String cpf; private String sexo; public Long getId() { return id; } public void setId(Long id) { this.id = id; } public String getNome() { return nome; } public void setNome(String nome) { this.nome = nome; } ...getters and setters I need to saving data in my mysql db, but i have some doubt about this code main how to get parameter send form html combobox( 1 for day, 2 for month, 3 for year of birth) i concatened with StringBuilder finalDate ... so i have some problem in my code please help me!!!

    Read the article

  • Servlet send image from server and save in client

    - by sangi
    Hi, I'm new and just developing on J2EE. I am modifying an existing application (an OpenSource project). I need to save an image on a client sent by the server, but I do not know how. This activity must be done in a transparent manner without affecting the existing operation of the application. From the tests done I get this error: java.lang.IllegalStateException: getWriter () has Already Been Called for this response. How should carry out this task, according to your own opinion? How do I save on the client, locally, the image? Update: Thanks for the answers. My problem is that: the image is generated on the server, but not for direct client request (there is no link to click on web page), the picture is composed using other services on the Internet. reconstruct the image on the server. This image must be sent to the client to be saved locally. so I'd like it to appear a window where you assign the destination image plus I'd like the rest of the application were not affected by this activity. The application is yet on production. Thank you very much for your response.

    Read the article

  • Proper way of naming your Java Google App Engine Project

    - by Saif Bechan
    I am starting out with Google's App Engine in Java. I have seen the tutorial video but I do not understand the naming of the project package. It is going to be a guestbook, that's why the name is guestbook, I understand that part. But after that I see package name. 1)Is that something you import into the project, or is is something you create. I have seen this a lot in projects, something like com.xxx.xxx. 2)How do you name this type of thing or is this an import. I have looked at another tutorial there they take the naming to a whole new level. The name of both the project and the package is de.vogella.gae.java.todo. 3)What does this mean in java terms. 4)Maybe one of you can help me with this specific project I want to start. I want to create a Google App project that for now only serves static files. I will leave the project empty and just put all my static files in the war directory of the project. I want the domain name to be mydomainstatic

    Read the article

< Previous Page | 8 9 10 11 12 13 14 15 16 17 18 19  | Next Page >