servlets

Grizzly + Static Content + Servlet Filter

╄→尐↘猪︶ㄣ 提交于 2020-01-05 08:45:30
问题 I can get Grizzly to serve static content I can create the servlet filter to filter a named servlet But I can't get the servlet filter to filter the static content. How do I do that? Here is the code I have so far: WebappContext webappContext = new WebappContext("grizzly web context", ""); FilterRegistration authFilterReg = webappContext.addFilter("Authentication Filter", org.package.AuthenticationFilter.class); // If I create a ServletContainer, I can add the filter to it like this: //

java.lang.ClassCastException: org.glassfish.jersey.servlet.ServletContainer cannot be cast to javax.servlet.Servlet

[亡魂溺海] 提交于 2020-01-05 08:36:08
问题 I'm unable to start my webapp on my Tomcat 7.0 Server because of the following error : java.lang.ClassCastException: org.glassfish.jersey.servlet.ServletContainer cannot be cast to javax.servlet.Servlet My web.xml , which include the ServlectContainer : <?xml version="1.0" encoding="UTF-8"?> <!-- This web.xml file is not required when using Servlet 3.0 container, see implementation details http://jersey.java.net/nonav/documentation/latest/jax-rs.html --> <web-app version="2.5" xmlns="http:/

Java Servlet Validation Confused

北战南征 提交于 2020-01-05 08:16:33
问题 I have noticed some problem when performing server side servlet validation given the form, i need to validate the firstname text field <form action="Test" method="POST"> <input type="text" name="firstname" /> <input type="submit" value="submit" /> </form> Servlet validation code that does not work for me. it always see firstname with length=0 not null if(request.getParameter("firstname")==null) { out.println("Error"); }` but after modifying the form adding enctype="multipart/form-data" to be

Show the number of pages in a pdf generated using itext only on the first page

試著忘記壹切 提交于 2020-01-05 07:44:32
问题 I am creating a PDF file using itext 2.1.7 and java servlets where I am inserting header and footer by overriding PdfpageEvents the onEndPage and onCloseDocument i am successfully able to put the pagev X of Y in the header/footer Now I want to calculate the cost of the pages (i.e. Cost of printing). So for that I need find the no. of pages in the pdf(i.e. Suppose printing of a page costs 3 I need to calculate the amount(3 * total no. of pages in pdf) for the entire pdf) and the catch is I

Preventing Tomcat from appending charset to binary content types

二次信任 提交于 2020-01-05 07:36:48
问题 We have a Restlet based service that returns the following response: HTTP/1.1 200 OK Server: Apache-Coyote/1.1, Restlet-Framework/2.0.7 X-Powered-By: Servlet 2.4; JBoss-4.2.3.GA (build: SVNTag=JBoss_4_2_3_GA date=200807181417)/JBossWeb-2.0 Content-Disposition: inline; filename=Time_for_a_breather.pdf Date: Fri, 13 May 2011 23:41:24 GMT Accept-Ranges: bytes Content-Type: application/pdf;charset=UTF-8 Content-Length: 218495 but unfortunately within some browsers (Chrome in particular) we are

Preventing Tomcat from appending charset to binary content types

六眼飞鱼酱① 提交于 2020-01-05 07:36:10
问题 We have a Restlet based service that returns the following response: HTTP/1.1 200 OK Server: Apache-Coyote/1.1, Restlet-Framework/2.0.7 X-Powered-By: Servlet 2.4; JBoss-4.2.3.GA (build: SVNTag=JBoss_4_2_3_GA date=200807181417)/JBossWeb-2.0 Content-Disposition: inline; filename=Time_for_a_breather.pdf Date: Fri, 13 May 2011 23:41:24 GMT Accept-Ranges: bytes Content-Type: application/pdf;charset=UTF-8 Content-Length: 218495 but unfortunately within some browsers (Chrome in particular) we are

Servlet filter mapped on /* results in browser error “server is redirecting the request for this address in a way that will never complete”

一曲冷凌霜 提交于 2020-01-05 07:22:10
问题 I am developing a dynamic JSP/Servlet web application. In order to handle the session, I am using a filter which is mapped on /* in web.xml . When I'm opening a page in Firefox, it gives the following Firefox-specific error message: Firefox has detected that the server is redirecting the request for this address in a way that will never complete A similar error is shown in Chrome. How is this caused and how can I solve it? 回答1: Your filter is redirecting to an URL which is invoking the very

Write Glassfish output into servlet html page

旧街凉风 提交于 2020-01-05 07:11:14
问题 How to redirect Glassfish server output into HttpServletResponse.out? I am making servlet in NetBeans. 回答1: here is a working example, just expose this as a servlet public class ReadLogs extends HttpServlet { private static final String CONTENT_TYPE = "text/html; charset=UTF-8"; public void init(ServletConfig config) throws ServletException { super.init(config); } public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response

Write Glassfish output into servlet html page

元气小坏坏 提交于 2020-01-05 07:11:03
问题 How to redirect Glassfish server output into HttpServletResponse.out? I am making servlet in NetBeans. 回答1: here is a working example, just expose this as a servlet public class ReadLogs extends HttpServlet { private static final String CONTENT_TYPE = "text/html; charset=UTF-8"; public void init(ServletConfig config) throws ServletException { super.init(config); } public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response

Javabeans with jsp:useBean. How do they work? I don't understand

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-05 07:10:39
问题 I have to get 2 numbers and an operation from a jsp file, using a java bean. After submitting the numbers, take them to a servlet from that Java Bean and return an result of them. Problem is that the java bean fields are never completed with the numbers written in textboxes. So, I have, index.jsp's body: <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>JSP Page</title> <link rel="stylesheet" type="text/css" href="style.css" /> </head> <body> <h1