servlets

How do I get the name of the WAR file?

折月煮酒 提交于 2020-01-03 09:05:10
问题 How can a class get the name of the WAR file that is using it? This is for diagnostic purposes. 回答1: in servlet String warName = new File(getServletContext().getRealPath("/")).getName(); you can use this. 回答2: ServletContext.getContextPath() This returns the context path of the application (or "" for the root context). Within a servlet container, no two applications will ever have the same value for this. EDIT: And for those who don't know what the context path is: it's the URI prefix for the

How to get the domain name from the request in a Java servlet?

南楼画角 提交于 2020-01-03 08:26:32
问题 If a single servlet serves data from two domains example1.com and example2.com , how do you retrieve the domain information from the request in a Java servlet? The purpose is to perform different actions depending on the domain. 回答1: Very easy, javax.servlet.ServletRequest.getServerName(). It also provides further methods to retrieve request information, getScheme() , getServerPort() ... Edit: If you have a web server guarding your application server, it must be configured to support this,

Proper way to stream live video feed from java servlet via ajax request

雨燕双飞 提交于 2020-01-03 07:01:08
问题 Im currently creating a custom surveillance application. And i was curious is it possible to take the live stream and and redirect it to a webpage via an ajax request. If so whats an example of how the ajax request would look. I'm working on the video feed aspect with java and was planning on using a servlet to push video feed to a request by the user whos on the appropriate webpage. 回答1: Only by using ajax + servlet you can not do that, but you need to have a media streaming server to

Generic Servlet to JSP Mapping

你。 提交于 2020-01-03 06:50:38
问题 I have a web app with many JSP files and want to remove the .jsp extensions from displaying in the URL without having to map each servlet to a similar page name. To do this I would like to redirect all servlets to a JSP file in a generic manner such as mapping /Login to /Login.jsp. I mapped all servlets to a filter as below. This works with respect to redirections to *.jsp except the end result is a blank page with the URL still containing the .jsp extension. <servlet> <servlet-name

How to upload Image at specific place or path?

孤街醉人 提交于 2020-01-03 06:39:20
问题 I am trying to upload Image but I can't. When my application is in local disk i.e. d:\ then it works. But when I put my application on out office server and when I am trying to upload image then it isn't working. Before I am using following path : final String path = "D:\\Workspace\\B2B Solution\\WebContent\\product_images\\"; now my application reside at : \\ADMIN\keyur\Workspace\B2B Solution\WebContent\product_images place i.e. on network. So which address I have to pass in servlet I don't

ava.lang.IllegalStateException: getOutputStream() has already been called for this response

ぐ巨炮叔叔 提交于 2020-01-03 06:31:10
问题 String contenttype = rs.getString("contentType"); String filename = rs.getString("fileName"); response.setContentType(contenttype); response.setHeader("Content-disposition","attachment;filename=" + filename.replace('"', ' ')); java.io.InputStream instream = rs.getBinaryStream("fileData"); byte[] b = new byte[1000]; while (instream.read(b) > 0) { try { response.getOutputStream().write(b); } catch(Exception e) {} } try { response.getOutputStream().flush(); } catch(Exception e) {} 回答1: Normally,

POST call to another server

China☆狼群 提交于 2020-01-03 04:51:06
问题 HI, Can we make the POST call from one server to another web server. For example, one web application deployed in server1. When we call the web application deployed in the server2, can we call using the POST method type. or always it can be GET method with explicit URLs 回答1: Two ways: If your current request is already POST, just send a 307 redirect. response.setStatus(307); response.setHeader("Location", "http://other.com"); This will however issue a security confirmation warning at the

content disposition with attachment doesnt work for AJAX response

一世执手 提交于 2020-01-03 04:16:07
问题 The problem for me is pretty straight forward. Onclick of an anchor tag , I execute a javascript using a4j:jsFunction and the action of this function should stream an XML file from server. The problem is , the stream sent on richfaces response doesnt give a saveAs dialog but instead renders the xml on the browser. After reading many articles I understood that Ajax response cannot give a saveAs Dialog. xhtml snippet: <h:form> <a4j:jsFunction name="updateCart" reRender="idFavouritePanel"> <a4j

How to redirect request from a filter to desired servlet with post DataParameter?

久未见 提交于 2020-01-03 03:29:05
问题 I am using following code to redirect a request from filter to servlet and jsp by using following snippet of code :- String redirectedServlet = "servletLcation"+"?parameter=abc"; response.sendRedirect(redirectedServlet.trim()); Here parameter is passing as get method . I want to pass this parameter as a post method . Is any way to do this ? My finding is as of now there is no way to send any parameter to any servlet by using response.sendRedirect() . response.sendRedirect() only support get

Servlet's service and init method are being called, but not doGet

大憨熊 提交于 2020-01-03 03:13:12
问题 I have a simple Servlet that looks like this: import java.io.IOException; import java.io.PrintWriter; 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; public class Bla extends HttpServlet { private static final long serialVersionUID = 16252534; @Override public void init() throws ServletException {