servlets

Jetty drops Cache-Control

独自空忆成欢 提交于 2020-01-07 06:48:31
问题 I'm having problem with deploying servlet on Jetty. It seems that Jetty simply drops Cache-Control (and Pragma ) headers produced in servlet. public abstract class Servlet extends HttpServlet { ... @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { ... resp.setHeader("Cache-Control", "private, no-cache"); resp.setHeader("Pragma", "no-cache"); ... } ... } All headers (esp. Cache-Control and Pragma) are as expected when I

HttpSession session=request.getSession(false); ruturning null

泪湿孤枕 提交于 2020-01-07 06:13:24
问题 my code is protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub HttpSession session=request.getSession(false); if(session==null){ response.sendRedirect(request.getContextPath()); }else{ doPost(request,response); } } the url pattern for this servlet is /loginServlet. i wrote this code so that if user is logged in and makes a get request by hitting enter on the url then the request must be

Calling Persistence.createEntityManagerFactory > 1 time

和自甴很熟 提交于 2020-01-07 05:29:11
问题 I have a servlet, and when I call this method with H2 specified in the PU, it re-creates all the database structure each time I call it. Can I only call this method 1 time, and if I can call it > 1 time, how do I do it? entityManagerFactory = Persistence .createEntityManagerFactory("MYPU"); XML for persistence <?xml version="1.0" encoding="UTF-8"?> <persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi

Giving File permissions and running ProcessBuilder in Java Servlets

你。 提交于 2020-01-07 05:26:09
问题 I have tried coding a servlet which creates a file based on the inputs given to it.The file gets created along with appropriate text but I am unable to give the file 777 permissions and I am also unable to run ProcessBuilder later. I thought it is inter related because the command fired in ProcessBuilder would require the file to have appropriate permissions but when I try giving it permissions using chmod it doesn't work either. import java.io.*; import java.util.Enumeration; import javax

android send location details to servlet via gps

好久不见. 提交于 2020-01-07 05:21:05
问题 i am newbie to Android..i have latitude and longitude details in my program..i want to send them to web server via gps..and those details should be saved in a database and retrieve them whenever i require..plz explain me how to do..and if possible give me some sample code... 回答1: Did you mean the mobile network or wireless instead of GPS ? Anyway: You from the sounds of it you need to get the GPS details into your program then pass them to your server. Have you designed your webserver yet or

web.xml ignoring main JSP file

荒凉一梦 提交于 2020-01-07 04:36:09
问题 I'm trying to create a servlet which loads "FirstJSP.jsp" in WEB-INF/jsp/FirstJSP.jsp I'm having a problem with my web.xml file. I've looked through dozens of forum posts both on SO and elsewhere, yet none of them work. Here's my current revision <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml

Add Http Basic Authentication to servletRequest

耗尽温柔 提交于 2020-01-07 04:14:26
问题 I have a ProxyServlet to handle requests to another server (which uses HTTP Basic Authentication) sent from my Application, and i want to add the header manually before the Servlet fires the actual request so the User wont have to enter any credentials. I have tried something like this code below using HttpServletRequestWrapper public class DataServlet extends ProxyServlet { @Override protected void service(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws

Avoid Scriptlets in Jsp for displaying data on page load

妖精的绣舞 提交于 2020-01-07 04:08:43
问题 I realize that when you submit the form in a jsp, in the mapped servlet you can get the desired data, set it in the proper scope(say request) and forward it to jsp like this: request.setAttribute("myList", myList); // Store list in request scope. request.getRequestDispatcher("/index.jsp").forward(request, response); However am wondering for pages which doesn't have a form or in other words we want to display data as soon as page loads, how can we efficiently load the data without using

Custom tag that evaluates its body based on the variables of the tag

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-07 03:24:25
问题 Ok, now this is something for the hard core JSTL wizards I guess ;-) I would like to have a tag whose body does not substitute the variables of the surrounding page. It should only take the variables into account that have been specified in the body of the tag or in the tag itself like this: <c:set var="outsideVar" value="outside value"/> <a:component> <%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %> <div data-component-id="9"> <c:set var="componentId" value="9"/> <c:set

JSP hand over text to java and another jsp [duplicate]

元气小坏坏 提交于 2020-01-06 19:55:38
问题 This question already has answers here : How to transfer data from JSP to servlet when submitting HTML form (4 answers) Closed 3 years ago . I have a JSP page with a textarea and a button, a servlet and a new jsp: My 3 problems are: My analysis.jsp is empty. My borwser opens a new tab but without the text "Hello World" The variable "sql" in my java class is empty too. It should contain the text from my textarea How can I hand over after my variable sql isn't empty (after analyze) new new code