servlet-3.0

How to use annotations instead of web.xml in the servlet to specify url

≯℡__Kan透↙ 提交于 2019-12-17 20:21:33
问题 How to provide an annotation mapping for web.XML in annotation. I have done with web.XML. I want to try with Annotation mapping, like so: <web-app> <servlet-mapping> </servlet-mapping> </web-app> 回答1: A simple example is : @WebServlet(value="/hello") public class HelloServlet extends HttpServlet { @Override public void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException { PrintWriter out = response.getWriter(); // then write the data of the

can't import javax.servlet.annotation.WebServlet;

可紊 提交于 2019-12-17 15:29:47
问题 I have started to write app that can run on Google App Engine. But when I wanted to use my code from Netbeans to Eclipse I had an errors on: import javax.servlet.annotation.WebServlet; and @WebServlet(name = "MyServlet", urlPatterns = {"/MyServlet"}) the errors are: The import javax.servlet.annotation cannot be resolved WebServlet cannot be resolved to a type I tried to import the servlet-api.jar to Eclipse but still the same, also tried to build and clean the project. I don't use Tomcat on

get value separately from json object in java servlet

房东的猫 提交于 2019-12-13 08:14:02
问题 this is my javascript code to send json object to servlet username = "Nash"; password = "619here"; type = "all"; data = '{ "username": "' + username + '", "password": "' + password + '", "type": "' + type + '" }'; request = JSON.parse(data); $.getJSON(url, request, function (response) { $("#result").append("<h1>Success</h1>"); $.each(response.vehicle, function (no, vehicle) { $.each(vehicle, function (key, value) { $("#result").append("<h2>" + key + " : " + value + "</h2>"); }); $("#result")

GSON with servlet

柔情痞子 提交于 2019-12-13 06:06:54
问题 My Folder Structure: Servlet: @WebServlet(name = "KPItoGSON", urlPatterns = {"/KPItoGSON/*"}) public class KPItoGSON extends HttpServlet { /** * Processes requests for both HTTP * <code>GET</code> and * <code>POST</code> methods. * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response)

Web Application that requires “servlet-3.0” cannot be added to Websphere Liberty Server, version 8.5.6 or v9 Beta

安稳与你 提交于 2019-12-13 05:50:54
问题 I am trying to connect a web application (downloaded from Github and imported into an Eclipse project) to a Websphere Liberty Server. I cannot add the application to the Liberty server because the application requires a servlet-3.0 feature, which is unsupported in the new and available releases. How do I get these features on this version of the Websphere Liberty server? 回答1: I think the optional step #3 on the Liberty download site has the information you need. https://developer.ibm.com

JEE6 Long Polling WebServlet - Exception after calling AsyncContext#complete

青春壹個敷衍的年華 提交于 2019-12-13 04:07:29
问题 I am trying to implement long polling, however after calling AsyncContext.complete() I get an exception from Weld: Warnung: Error invoking requestDestroyed method on ServletRequestListener org.jboss.weld.servlet.WeldListener java.lang.NullPointerException at org.jboss.weld.context.AbstractBoundContext.deactivate(AbstractBoundContext.java:71) at org.jboss.weld.context.http.HttpRequestContextImpl.deactivate(HttpRequestContextImpl.java:70) at org.jboss.weld.servlet.WeldListener.requestDestroyed

Error pages with Servlet 3.0

懵懂的女人 提交于 2019-12-12 22:10:25
问题 In the web.xml file, I'm trying to specify an error page as follows. <error-page> <location>/WEB-INF/jsp/admin/ErrorPage.jsp</location> </error-page> I expect it to go without an error code according to Servlet 3.0 but it doesn't. I have to explicitly specify an appropriate error code for it to work something like the following. <error-page> <description>Missing page</description> <error-code>404</error-code> <location>/WEB-INF/jsp/admin/ErrorPage.jsp</location> </error-page> Why doesn't the

Deployed Simple HelloWorld with Spring MVC app (without web.xml) gives 404 error

主宰稳场 提交于 2019-12-12 12:36:00
问题 I am newbie to Spring MVC with annotations, I have worked with Spring MVC XML Configuration earlier. I get 404 error when I try to hit the url http://localhost:8080/HelloWorldApp. I have written three classes: 1. AppIntializer 2. AppConfig 3. AppController Following piece of code: package com.demo; public class AppIntializer implements WebApplicationInitializer { private static final String CONFIG_LOCATION = "com.demo.config"; @Override public void onStartup(ServletContext servletContext)

Servlet 3.0 logout doesn't work

女生的网名这么多〃 提交于 2019-12-12 12:08:29
问题 I've got a problem with the authentication features of Servlet 3.0: With this code in a Servlet v3: log.info(""+request.getUserPrincipal()); log.info(""+request.getAuthType()); log.info("===^==="); request.logout() ; log.info(""+request.getUserPrincipal()); log.info(""+request.getAuthType()); request.authenticate(response) ; log.info("===v==="); log.info(""+request.getUserPrincipal()); log.info(""+request.getAuthType()); I would always expect to see the Username/login windows, because of the

AsyncContext and I/O error handling (when peer disconnects)

人盡茶涼 提交于 2019-12-12 07:19:15
问题 I'm implementing Server-Sent Events using Servlet 3.0's javax.servlet.AsyncContext interface. However I can't understand how I should handle I/O errors like peer disconnect. For a given AsyncContext ac = request.startAsync() , I can call ac.getResponse().getWriter().print(something) and then ac.getResponse.getWriter().flush() and it works fine. However when a client disconnects, I don't get an error - even if I attach a listener, its onError method is not called. I tested it with both Jetty 8