servlets

Character encoding in query string, hebrew

杀马特。学长 韩版系。学妹 提交于 2019-12-29 08:51:31
问题 I am trying to send a GET request with query string parameter in hebrew. When the controller gets the request, the parameter is in gibberish. i've added "org.springframework.web.filter.CharacterEncodingFilter" but it didn't change a thing. Please advise how to fix it. Update: here is the the request. GET /myapp/specialties?query=%D7%92%D7%99%D7%A0%D7%A0%D7%A0%D7%A0 HTTP/1.1 Host: localhost:8080 Connection: keep-alive Accept: * Cache-Control: no-cache User-Agent: Mozilla/5.0 (Macintosh; Intel

Custom error page - get originally requested URL

让人想犯罪 __ 提交于 2019-12-29 08:44:12
问题 Problem This is a follow-up to yesterday's (unanswered) question (see here) as I try to find an alternative approach. I added the basic <error-page> <error-code>404</error-code> <location>/404search.jsf</location> </error-page> ..to my web.xml . I now need to get the URL the user entered to submit to my search function, but I only manage to get the current URL (in this case, ... 404search.jsf ) instead of the actual query the user entered. Attempts HttpServletRequest.getRequestURL returns

HttpSessionListener.sessionCreated() not being called

折月煮酒 提交于 2019-12-29 08:18:15
问题 I have a very simple Servlet and a very simple HttpSessionListener: @WebServlet("/HelloWorld") public class HelloWorld extends HttpServlet { private static final long serialVersionUID = 1L; @Override public void init(ServletConfig config) throws ServletException { super.init(config); getServletContext().setAttribute("applicationHits", new AtomicInteger(0)); } protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { System.out

out.println says out cannot be resolved

心不动则不痛 提交于 2019-12-29 08:13:06
问题 When I write out.println() , eclipse complains that out cannot be resolved. I have imported java.io.* and other servlet packages. 回答1: Just a shot in the dark, I think this is the out you are looking for: public class OutServlet extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { PrintWriter out = response.getWriter(); out.println("foo"); } } 回答2: You should write System.out.println(); inside a function. If

out.println says out cannot be resolved

早过忘川 提交于 2019-12-29 08:13:01
问题 When I write out.println() , eclipse complains that out cannot be resolved. I have imported java.io.* and other servlet packages. 回答1: Just a shot in the dark, I think this is the out you are looking for: public class OutServlet extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { PrintWriter out = response.getWriter(); out.println("foo"); } } 回答2: You should write System.out.println(); inside a function. If

Spring 4 websocket + Tomcat 7.54 async-supported not working

偶尔善良 提交于 2019-12-29 07:54:30
问题 I am creating a sample chat application using the Spring websockets and stomp.js , I am using the tomcat 7.54 but while runing the application I am gettting a async-supported error when browser is making xhr request. Server info: Apache Tomcat/7.0.54 Servlet version: 3.0 JSP version: 2.2 Java version: 1.7.0_25 Web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=

Missing Elements in HTTP Request - Null or Empty?

丶灬走出姿态 提交于 2019-12-29 07:47:07
问题 I have a HTTP Request javax.servlet.http.HttpServletRequest that is passing in a value to be used in some code being handled in a Java web service using JAX-RS. The POST function in Java is consuming application/json . There are two possible values to be passed into the request, call one X and the other Y , assume both are Strings. The request requires at least one of the two possible values to be considered 'valid'. When the request comes in, if X is provided and Y is left out of the request

How to run different apps on single JBoss AS 6 instance behind different ports?

孤者浪人 提交于 2019-12-29 07:39:08
问题 I am coming from this SO however my case is not on Tomcat, but JBoss EAP 6. So suppose I have two web apps app1 and app2 running on JBoss AS 6: app1 on http://localhost:8080/app1 app2 on http://localhost:8080/app2 However I want to configure Tomcat so that they run in root context behind separate ports: app1 on http://localhost:8081 app2 on http://localhost:8082 How can I make it on JBoss EAP 6? Note this answer doesn't work for me as it targets JBoss 5. 回答1: EDIT: These instructions are for

Retrieve images from a folder outside web root folder using servlet

一个人想着一个人 提交于 2019-12-29 07:16:19
问题 I'm trying to create a small servlet that uploads images and is able to retrieve them in a different page as a slideshow. I'm able to save them outside the WebApp folder, but while retrieving them I need them to be a part of a JSP which will have other content, apart from the images. Currently, I'm using BufferedImage and ImageIO classes to stream the images one at a time. BufferedImage image = ImageIO.read(new File("D:\\"+file.getName())); ImageIO.write(image, "jpg", response.getOutputStream

Servlet: Cannot forward after response has been committed

為{幸葍}努か 提交于 2019-12-29 06:33:10
问题 I'm working on servlet page that renders content based on geo-location , and I want to use both sendRedirect and forward together; e.g; you browse example.com/aPage.jsp from France ; first I want the servlet to redirect you to example.com/fr/aPage.jsp and then forward you to the resources page. This is what I have in my servlet: public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { .... response.sendRedirect(REDIRECT_URL_BASED_ON