servlets

How to send a file from a servlet the “right” way?

吃可爱长大的小学妹 提交于 2019-12-30 07:21:09
问题 I'm trying to send a file to a user from an http servlet. The servlet runs some identification tests (on the request) and then sends the client a file. This generally works but now I turned on my TOMCAT server redirects to https and when I try to access the servlet and download the file from either IE6 or IE8 it fails and I get this exception: java.lang.IllegalStateException: Cannot forward after response has been committed (on the localhost.log) and ClientAbortException: java.net

How to compile servlets from command prompt?

℡╲_俬逩灬. 提交于 2019-12-30 07:15:10
问题 I'd like to compile a very basic servlet from command prompt, but it is always unsuccessful and the compiler tells me the following: error: package javax.servlet does not exist. I googled for the solution and I found that I need to include the servlet.jar libraries into my PATH. I believe I did. I strongly believe that the location for those libraries in my computer is: C:\apache-tomcat-7.0.23\lib\servlet-api.jar\ and the end (the relevant part) of my PATH is the following: %JAVA_HOME%\bin;C:

Passing data from servlet to another servlet using RequestDispatcher

别说谁变了你拦得住时间么 提交于 2019-12-30 06:35:55
问题 I am trying to pass data from one servlet to another using the RequestDispatcher. This is my code for the Dispatcher. String address; address = "/Java Resources/src/coreservlets/MapOut.java"; RequestDispatcher dispatcher = request.getRequestDispatcher(address); dispatcher.forward(request, response); When I try to run it, it gives me an error saying the path is unavailable. Do I have to include something for the dispatcher to send to another servlet? 回答1: You just need to pass servlet-mapping

Servlet containers and classpath

泪湿孤枕 提交于 2019-12-30 06:00:36
问题 To what is the class path of a Servlet container set? As per my understanding there are three components involved. The JAR files in the lib directory of the Servlet container and then the classes in the WEB-INF/classes and JAR files in the WEB-INF/lib directory. The classes in lib directory of the Servlet container are added to the system classpath and the dynamic classpath includes the JAR files in the lib directory and classes in the classes directory. To what is the dynamic classpath set?

Order of request.getParameterNames()

无人久伴 提交于 2019-12-30 05:57:39
问题 How do I get all the parameterNames in an HTML form in the same sequence as they are in the form. i.e if the form contains .... FirstName, LastName, MiddleName and Age . the output should appear in the same sequence I have tried using the following but this shifts the order of the output: Enumeration paramNames = request.getParameterNames(); while(paramNames.hasMoreElements()) { String paramName = (String)paramNames.nextElement(); out.print(paramName); } 回答1: I don't think there's nothing in

ServletContextListener not being invoked

亡梦爱人 提交于 2019-12-30 05:54:46
问题 I creating a Java EE 7 project using Eclipse Maven plugin. My problem is when I run the application the class that implements SerlvetContextListener does not get invoked. What is causing this problem? @WebListener public class ApplicationContextListener implements ServletContextListener{ @Override public void contextInitialized(ServletContextEvent sce) { Request request = new HttpRequest(sce); new Thread (request).start(); HibernateUtil.getSessionFactory(); } @Override public void

How to write response filter?

旧巷老猫 提交于 2019-12-30 05:27:04
问题 Is there a way to handle only response in a filter . Is the code written below correct ? public void doFilter(request , response , chain) { //code to handle request chain.doFilter(request, response); //code to handle response . } 回答1: It depends on what you want. In general, your sample is not correct though. After chain.doFilter has returned, it's too late to do anything with the response. At this point, entire response was already sent to the client and your code has no access to it. What

JSP Servlet and Web Programming

喜欢而已 提交于 2019-12-30 05:23:27
问题 I use Java mostly for GUI programming and PHP for web programming but I really don't like not having a statically typed language. For my next project I would like to use Java instead of PHP. What is the difference between JSP and servlets? 回答1: JSP basically allows you to write your Java code around HTML, superficially seeming like PHP or ASP. The result is just compiled to a servlet though. 回答2: Under the covers JSP and Servlets are esentially the same, both compile to servlets and both

Accessing ServletContext outside of a servlet

我的梦境 提交于 2019-12-30 05:19:05
问题 I wonder if anyone can advise on a Java webapp question? I have a set standard Java class which has methods to set and get values of a property file. These methods are used system wide and are called by servlets and non-servlet class methods alike. But what I would like to do is to use a ServletContextListener to set the paths to the property file globally rather than hard code them or store them in the database. A ServletContextListener can be used to set 'global variables' for the servlets

jsp getServletContext() error

ⅰ亾dé卋堺 提交于 2019-12-30 05:08:06
问题 html <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Murach's Java Servlets and JSP</title> </head> <body> <%-- import packages and classes needed by the scripts --%> <%@ page import="business.*, data.*" %> <% //get parameters from the request String firstName = request.getParameter(