FAQ Database Discussion Community


No NullPointerException in JSTL when calling methods on null object associated with request object.why?

java,jsp,servlets,nullpointerexception,dispatcher
Yesterday I appeared in an interview. The interviewer shows me this code and asked- <c:when test='${hobby.equals("hobby1")}'> Why there is no null pointer, while the value of hobby is null Code is as- In Sevlet class- request.setAttribute("hobby", null); request.getRequestDispatcher("display.jsp").forward(request, response); In display.jsp- <c:when test='${hobby.equals("hobby1")}'> ...

After redirect code still executing from previos page

java,jsp,servlets
How System.out.println("") is executed after response has been redirected to other resource. In my code: res.sendRedirect("/more_value_in_param/display.jsp"); System.out.println("to avoid penalty and disconnection"); Why in console to avoid penalty and disconnection is being displayed since response has been already redirected to display.jsp?...

when is servlet response committed or flushed?

java,jsp,servlets,forward,requestdispatcher
According to javadoc: in-request.getRequestDispatcher("/Test").forward(request,response); forward should be called before the response has been committed to the client (before response body output has been flushed).Uncommitted output in the response buffer is automatically cleared before the forward. I am getting confused when this response is committed or been flushed? is this writing...

HTTP Status 500 - Servlet execution threw an exception (java.lang.ClassNotFoundException)

java,jsp,servlets,twitter
I have been getting this resource not found error and I'm not able to figure out whats wrong with my code. Here is my code. TwitterServlet.java: package com.dhruvil.jsw; import java.io.IOException; import java.util.ArrayList; import java.util.List; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.poi.xssf.usermodel.XSSFSheet; import org.apache.poi.xssf.usermodel.XSSFWorkbook; import twitter4j.Status;...

Session attribute is null at first load

java,jsp,servlets
I have the following servlet: @WebServlet(name = "Placeholder",urlPatterns = {"/foo"}) public class Placeholder extends HttpServlet { public static int numbers=5; HttpSession session; public void doGet (HttpServletRequest _req, HttpServletResponse _res) throws ServletException, IOException { /* Refresh session attributes */ session = _req.getSession(); session.setAttribute("wee","ok"); } } With the following JSP: <[email protected] language="java"...

Initialize class with constructor in

jsp,servlets,usebean
I am trying to initialize a class by passing a parameter to the constructor. I need the scope to be "page". I know I have one argument in my constructor, but how do I have one that accepts parameter using <jsp:useBean>, and can be called from a JSP page? public...

How to find servlet API version for glassfish server?

java,java-ee,servlets,glassfish
While coding a servlet I found a method that says Since: Servlet 3.1 I guess that if I have the autohint from NetBeans to use it is because I have that Servlet version. But I cannot find a place to confirm that. I'm using glassfish4.1 as container. If I go...

JSTL not printing my passed attribute from servlet. Is scope or not accessing doGet() the issue?

jsp,servlets,foreach,jstl
I'm making a simple blog application. User enters an announcement, its passed to servlet where it is inserted into a database in the POST method via DAO. The GET method creates an arrayList by retrieving all the data via the same DAO and passing it to the view page. Not...

Difference between Threads created by web container and Normal Threads?

java,multithreading,servlets,web-container
May i know how are Threads created by web container (New thread is created for every request) different from normal Threads which are created by Extending Thread Class or implementing Runnable Interface. Also how does Web container create Threads,even when Servlet interface or the servlets Extending it doesn't contain any...

How to check Glassfish4 server is overloaded?

jsp,java-ee,servlets,glassfish,servlet-filters
My java web application runs on Glassfish4. I want to show a webpage have the string - Server too busy. Please try again later. Which solution is the best for this case?...

What is 'service' method in HttpServlet class?

java,servlets
Below is a simple servlet written for learning. package com.example.tutorial; import java.io.IOException; import java.io.PrintWriter; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; public class ServletExample extends HttpServlet { private static final long serialVersionUID = 1L; protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { PrintWriter out =...

package javax.servlet.annotation does not exist while using jboss [duplicate]

java,jsp,maven,servlets
This question already has an answer here: The superclass “javax.servlet.http.HttpServlet” was not found on the Java Build Path 13 answers I am using Jboss 7. I added a servlet to my project. I have added the servlet-api.jar in my library I have added dependency for servlet-api.jar in my pom.xml...

I want to call a Servlet as a very first file

java,jsp,servlets
I want to call a Servlet as a very first file to execute like welcome file. In this servlet I am retrieving data from database and rendering it to display page at a very first page. what I need is when I run program either url should be-http://localhost:8083/projectName/servletUrl not http://localhost:8083/projectName/...

How to use two port numbers for a single java web application?

java,eclipse,tomcat,servlets,port
I am working in a java web project in Eclipse IDE. project is working fine and we use Apache tomcat 7 as server. Now to access the application we use the URL as localhost:8080/APPNAME/. It works fine. In my project there is a servlet, that will request by other java...

How to intercept Spring MVC serialized response?

java,spring,spring-mvc,servlets,interceptor
I want to intercept Spring servlet response just at the end of the request. I mean, what i want to do is to log service response, that json which services returns and the statusCode. That is all what i want to log. For that, i've already tried using HandlerInterceptorAdapter like...

How does a servlet handle more bytes than available RAM?

java,performance,servlets,jvm
Lets say that I have a servlet running that accepts files of any size from a client application(s). The file being sent is loaded into a DataHandler and is transmitted by web-services; as such is received and put back into a DataHandler. What happens if the file being sent exceeds...

How to multiply values from different coloumn in jsp servlet

jsp,servlets
I want to multiply resultSet.getInt("price") with resultSet.getInt("quantity") And give the result in my html How can i do it? P.s im a beginner...

Bad Operand types for binary operator '/' first type String second type int

java,jsp,servlets,web-applications,javabeans
New to javabeans so please forgive me if this is simplistic: Getting this error while writing a javabean page. The code basically asked to add 7 values together and then divide the total by 160. Code is: public String getAverage(){ return (Str1 + Str2 + Str3 + Str4 + Str5+...

download jasper report to a specific location in the server

java,servlets,jasper-reports
My application is running in a tomcat server, and I have already developed a method to download a pdf file using jasper. What i need to do is, download that certain pdf to a location inside the server. I tried and I am not sure how to do it. jasperReport...

Internal Server error while calling an Java method from JSP

java,jsp,servlets,struts,struts-config
This is my JSP extra.jsp: <[email protected] uri="http://struts.apache.org/tags-bean" prefix="bean"%> <html> <head> </head> <body> <h1><bean:write name="HelloWorldForm" property="message"> </h1> </body> </html> this formBean HelloWorldForm.java: package com.redhat.rhn.frontend.action.common; import org.apache.struts.action.ActionForm; public class HelloWorldForm extends ActionForm{ String message="HelloWorld!"; public String getMessage() { return message; } public void...

Tomcat - redirect old context root to new context root

java,tomcat,servlets,contextroot
We want to change the context root of a Tomcat web appplication and have the old URL guide users to the newly named application. http://hostname/oldappname http://hostname/newappname One way to do this would be deploy the application with a context root of newappname and another application with a context root of...

How to transform $.post to $.ajax?

javascript,jquery,ajax,json,servlets
I have this $.post peace of code: $.post("../admin-login", { dataName:JSON.stringify({ username:uname, password:pass, }) }, function(data,status){ console.log("Data:"+data); answer = data; } ); and I wont to transform it to $.ajax. On the servlet side I am demanding request.getParamter("dataName") but I do not know how to write data: section in $.ajax so...

how can I create a URL/site to send a HTTP 204 or HTTP 403 response?

objective-c,http,servlets,post,ios7
I'm trying to create an app with a login page to POST to a url and return a status code. For now the app is to call a URL that returns a HTTP 204 or HTTP 403 response. How is this done? Do I need to create/implement a servlet?

How to get a Http Session while a servlet is being initialised? [duplicate]

jsf,servlets,lifecycle,httpsession
This question already has an answer here: How do servlets work? Instantiation, session variables and multithreading 6 answers we can get the session if we can access to HTTP request object like below: HttpSession session = request.getSession(); But, How to retrieve the HTTP session inside init method of Servlet...

init method is calling again and again in servlet

java,servlets
The init method gets called again and again on every request in servlet. Here is the code: public class PersonInfoController extends HttpServlet { private static final long serialVersionUID = 1L; public PersonInfoController() { super(); } public void init() throws ServletException { Connection connection = Database.getConnection(); System.out.println("init method"); } protected void...

Ajax response doesn't display in JSP page

java,jquery,ajax,jsp,servlets
I'm Trying to Save small record using JSP ajax in technology. The project working procedure is like this. 01. index.jsp : Send data to SaveStudent servlet 02. SaveStudent : Get request form jsp and send it to validation java class 03. Validation : Validate data and Send to DaoImpl java...

Java Servlet - get parameters with same name

java,java-ee,servlets,post
I know that I can get parameter like: HTML <input type="text" name="field" value="test"> Servlet String field = request.getParameter("field"); But what if I have multiple input with same name like: HTML <input type="text" name="line[]" value="test1"> <input type="text" name="line[]" value="test2"> <input type="text" name="line[]" value="test3"> In PHP I can just use name="line[]" to...

The type javax.servlet.ServletContext and javax.servlet.ServletException cannot be resolved

java,maven,servlets,spring-security
I'm trying to include Spring Security to my web project, i'm following this tutorial http://docs.spring.io/spring-security/site/docs/current/guides/html5//helloworld.html I've done everything in the tutorial with the given maven project and works fine. But when i'm trying to include it to my project a compilation error appear. Specifically when i extends from AbstractSecurityWebApplicationInitializer appear...

How to receive json object from servlets with ajax?

java,jquery,ajax,json,servlets
doGet sets item readState new value and sends it back to ajax call as Json object: PrintWriter out = null; try { out = resp.getWriter(); Integer read = Integer.parseInt(req.getParameter("feedReadVal")); Gson data = new Gson(); JsonObject jsonObj = new JsonObject(); Integer readState = null; Item item = new Item(); readState =...

Drag and drop zone in JS - File input

javascript,jquery,html,servlets
I have problem with uploading files in my existing form. What I am looking for is script that will make possible to add multiple files (max 5) and you can add at once from one to five files. If you add one by one, I need it to add new,...

weblogic 12c basic authentication not prompting for userid

java,java-ee,servlets,weblogic,weblogic12c
I am trying to configure basic authentication for a servlet deployed on Weblogic 12c. Here is my web.xml <security-constraint> <web-resource-collection> <web-resource-name>TestServlets</web-resource-name> <url-pattern>/ReasonServlet</url-pattern> </web-resource-collection> <auth-constraint> <role-name>TestServiceRole</role-name> </auth-constraint> </security-constraint> <login-config> <auth-method>BASIC</auth-method>...

Login page filter problems

jsp,servlets,servlet-filters
I'm trying to apply a filter to my login page. I'm just not sure how it works, since I'm not too familiar with filters. I'm trying to redirect a user that logs in to different pages based on their user type. A user has either the user type 'Customer', 'Owner'...

How to configure Servlet on Tomcat Server and fix javax.naming.NameNotFoundException?

java,tomcat,servlets,web.xml,catalina
Recently I deployed an app to Tomcat Server. It's not working because the app can't find the Servlet. I thought the servlet-class in web.xml was okay but apparently the syntax/mapping is wrong since they cant find it... web.xml <servlet> <servlet-name>ControllerServlet</servlet-name> <servlet-class>controller.ControllerServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> catalina.log INFO myapp.com-startStop-2 org.apache.catalina.startup.HostConfig - Deployment of...

Is there any better approach to generate radio button?

jsp,servlets,jstl,el
To generate dynamic radio button based on value in hobby.What i does is- request.setAttribute("hobby", null); //values of hobby can be "hobby1" or "hobby2" or "hobby3" or null request.getRequestDispatcher("display.jsp").forward(request, response); In display.jsp I am generating radio button- <tr> <td >Hobby1 <c:choose> <c:when test='${hobby.equals("hobby1")}'> <input type="radio" value="hobby1" name="hobby" checked/> </c:when> <c:otherwise> <input...

Unable to include servlet response by using requestDispathser

java,jsp,servlets,requestdispatcher
Index.jsp <form method="post" action="serv"> Enter Latest Reading <input type="text" name="t1"> <br> Enter Previous Reading <input type="text" name="t2"> <br> <input type="submit" value="SEND"> </form> LoginServlet.java @WebServlet("/serv") public class LoginServlet extends HttpServlet { protected void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { PrintWriter out = res.getWriter(); out.println("<u>Following are your Bill...

Use Scheduler to execute/access task from Servlet

java,servlets,timer,cron4j
What I would like to do: If a user on my web application (tomcat, java) performs an action and 1 week passes before he performs it again, I would like to send him an email. For example, someone performs a "like" on jan 1, 2015 then performs another "like" on...

Clicking Refresh Servlet Page Shows Repetitive Content

java,mysql,servlets
I am on my first servlet program and I have created a page to list the rows of a table from database. Whenever I click the refresh button, the page displays repeated results. How can I overcome it, any suggestions? @WebServlet("/BookList") public class BookList extends HttpServlet { private static final...

Jersey resource that matches any path

java,servlets,guice,jersey-1.0
I am using Jersey v1.x and a Guice Servlet. What I'm trying to do is bind a Jersey Resource that matches any @Path, such that I can use Jersey to respond with a 404. I'm looking to do this, since my servlet consists of different components (e.g. a rest API...

Print and println aren't executed in the same time

java,jsp,servlets,printing,println
I have a method in my servlet where I have some prints to the console.. private void collectingWorkPositions(HttpSession session, HttpServletRequest request) { System.out.println("Collecting1.."); //code... System.out.println("Collecting2.."); //code... System.out.print("printing p: "); for(Integer i:p) System.out.print(i + " "); } When this method iscalled, only Collecting1.. Collecting2.. are printed in the console. When I...

Tomcat filter not being invoked for Atmosphere servlet

java,tomcat,servlets,servlet-filters,atmosphere
I'm using Atmosphere 1.0.15 to handle push notifications under Tomcat and it's been been working fine for a few years now. Recently I added a simple filter to my Tomcat as a test, which (currently) just logs the incoming URL and continues. The problem is it the filter appears to...

Spring - Modifying headers for every request after processing (in postHandle)

java,spring,spring-mvc,servlets
What I want to do is, adding a new header to the response after the request is processed. I need to check the processed HttpStatus code (401 unauthorized in my case) and add a new header. I know Spring has interceptors, but the response cannot be modified as stated in...

Session Object is returning Null

java,servlets
public class FirstServletClass extends HttpServlet{ /** * */ private static final long serialVersionUID = -45872253821246793L; public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException ,IOException { response.setContentType("text/html"); PrintWriter pw = response.getWriter(); HttpSession session = request.getSession(); if(request.getParameter("userName")!=null){ session.setAttribute("UserName", request.getParameter("userName")) ; } pw.print("HI From Server <br/>"); pw.print("Accessing Value...

Remove empty tags at XML using Java

java,xml,servlets
I'm giving some functionality to a servlet, one of the things I want to do is, when receiving the InputStream (which is basically a PDF document parsed into an XML format) set that data to a String object, then I try to delete all the empty tags, but I haven't...

How to use Sping AOP to run code before every call of service method in Servlet

servlets,spring-aop
i have some common code must be injected into service method of any servlet . Thus, i build a mother servlet SuperController : public class SuperController extends HttpServlet{ private HttpServletRequest lastRequest ; //........ public void service(HttpServletRequest req,HttpServletResponse res){ setLastRequest(req); // example of common code } } THen, all other servlets...

Execute servlet on startup of the application

java,servlets
I build a web application with JSPs and in my servlet I have: public class MyServlet extends HttpServlet { protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { init(); HttpSession session = request.getSession(true); //more code... } } Till now my serlvet is called, when the JSP page calls it...

Tomcat servlet the requested resource is unavailable

java,tomcat,servlets
I am very unfamiliar w/ servlets and have been asked to write a simple a simple program on tomcat 7 using java. I wrote a very simple hello world program and haven't been able to get it running and need some help. import java.io.*; import java.util.*; import javax.servlet.*; import javax.servlet.http.*;...

How exactly are the root context and the dispatcher servlet context into a Spring MVC web application?

java,spring,spring-mvc,java-ee,servlets
I am studying Spring MVC and I have some doubt related So, I have this configuration class that configure my DispatcherServlet that handle the user requests: public class MyWebAppInitializer implements WebApplicationInitializer { @Override public void onStartup(ServletContext container) { // Create the 'root' Spring application context AnnotationConfigWebApplicationContext rootContext = ... //...

Creating GSON object error

java,servlets,gson
I'm trying to create Gson object inside Java Servlet class. public class SendNews extends HttpServlet { @Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { System.out.println("Before creating"); Gson gsonObj = new Gson(); System.out.println("This line and the whole code below will be skipped."); System.out.println("And this method will be finished...

How to send automatic mail from java Servlet using gmail id?

java,email,servlets
I am trying to send an automatic mail from java servlet to the gmail id.i used the following class for it. import javax.mail.*; import javax.mail.internet.InternetAddress; import javax.mail.internet.MimeMessage; import java.util.Properties; public class EmailTest { public void sendEmail(){ String to="[email protected]"; String host="mail.javatpoint.com"; final String user="[email protected]"; final String password="password"; //Get the session object...

CQ5 SlingServlet and resourceTypes not working for specific resource paths

servlets,cq5,aem,sling
If I define a Sling Servlet as follows: @SlingServlet( label="TestResourceTypeServlet", name = "com.company.project.servlets.TestResourceType", extensions = {"bob"}, resourceTypes= {"cq:Page"}, methods= {"GET"}, metatype=true) @Properties({ @Property(name = "service.description", value = "A test servlet"), @Property(name = "service.vendor", value = "Company") }) The servlet picks up any get request to every page with an extension...

Servlet ClassNotFoundException when present in a package … Why?

java,servlets,classnotfoundexception
When i am keeping the "MyServletProgram" in "java" package i get ClassNotFoundException java.MyServletProgram but when it is in default package, the program runs fine. Can you suggest where i am going wrong?? ...

Browser doesn't show dynamically generated CSS in JSP

css,servlets,dynamically-generated
I'm writing simple web app which generates simple CSS file for user. I've mapped servlet for writing CSS on specific tag, and depending of the user's session attributes, I use PrintWriter for generating CSS stylesheet. Problem: Stylesheet doesn't have any effect. Chrone shows it was downloaded (inspect element -> network),...

Included CDI-enabled Servlet Fails with ContextNotActiveException: WELD-001303:

java,tomcat,servlets,cdi,weld
I am writing a CDI application that runs on Tomcat. I am using Tomcat 7.0.62 with Weld 2.2.12.Final as the CDI implementation. I am using CDI without JSF. The application consists of a dispatcher servlet that is not CDI enabled. The dispatcher includes the output of a CDI enabled servlet...

Java HttpServlet, override method service, best practice

java,servlets
For logging purposes, I override the service method from HttpServlet like this: @Override protected void service(HttpServletRequest req, HttpServletResponse resp) { logger.debug("enter servlet"); logger.debug("Request Header: {}", MyHttpTools.requestHeaderToSting(req); super.service(req, resp); logger.debug("leaving servlet"); logger.debug("Response Header: {}", MyHttpTools.responseHeaderToSting(resp); } I found some places in the web, where authors say "don't override service". What do...

how to manage multiple war application in tomcat server?

java,maven,tomcat,servlets
I use tomcat as web server,I want to deploy many same war file in tomcat server with different config. How to do this in the best way possible manner? So I want to run tomcat server per each war application, my means is tomcat1 handle the .war1 in webapp and...

Which Should i use for date,time,email in servlet?

java,html5,java-ee,servlets
In servlet we use for text data String uname=request.getParameter("uname"); For numeric data we use int contact=Integer.parseInt(request.getParameter("contact")); Which should i use for email,date and time in servlet? Actually I'm using HTML5 where I use email as <input type="email" id="txtEmail" name="email" required> Date as <input type="date" id="dateBirthday" name="birthday" required> Time as <input...

AJAX call to Servlet Google App Engine (GAE)

java,ajax,jsp,google-app-engine,servlets
I am trying to make an AJAX call to my servlet but it doesn't work. I can't redirect to a JSP. This is my AJAX call: $.ajax({ url: '/register', type: 'GET' }); This is my Servlet: public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException { getServletContext().getRequestDispatcher("/prueba.jsp").forward(req, resp); } If...

Custom jsp tag is not invoked

java,jsp,servlets
I'm trying to write custom jsp tag. But my tag is not invoked. Instead I got response in plain text with my html and jsp tags(maybe browser doesn't parse it as html because of jsp tags). My tld file is in the right place(/WEB-INF/custom.tld) and I have no errors or...

Downloading file from Java servlet gives null

java,file,servlets,stream
I am trying to create a method that allows users to download a file on the file system via a Servlet. Right now, the correct filename shows on the download and a file is downloaded but the contents of the file are always null. I've also tried to get the...

Servlet to jsp on button click - whats the error?

java,jsp,servlets
I have a simple form on a jsp page, as given below. On clicking the button, it should take us to a servlet by the name of LoginValidation. But it doesn't work. <form name="login_form" action="LoginValidation" method="get" onsubmit="return func()" > <input type="text" placeholder="Username" id="username" class="style-4" /> <input type="password" placeholder="Password" id="pass" class="style-4"...

Search a table with the result of another search in servlet

java,sqlite,servlets
I have a table TABLE1 with 2 fields id and shift and another table TABLE2 with 3 fields id, name, surname. The field id is the same an the primary key in both tables. In my servlet I want to select all the id's which have shift != noon. so...

Username and password validation from database to jsp view page

java,javascript,jsp,servlets
If the username and password retrieved from database are incorrect then I would like to show error on jsp page itself instead of re-directing to another page. Right now I am showing a message from the validation servlet if the username and passwords are invalid. How do I show a...

Adding JQuery to java servlet

java,jquery,servlets
out.println("<html>"); out.println("<head>" + "<script src=\"http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js\"></script>" + "<script>" + "$('input[type=\"checkbox\"]').on('change', function(){$('input[type=\"checkbox\"]').not(this).prop('checked', false);});" + "</script>" + "</head>"); out.println("<body>"); I want to check only 1 checkbox at a time and would like to use this script to do that. The script itself is working, however in the servlet it isn't. How can...

Printing an ArrayList in HTML and matching each item with an input box

java,html,jsp,servlets,arraylist
I'm working on a piece of code where I have an ArrayList of items. I'm putting this on a webpage using HTML, and I want to print all the items in a list with an input field next to each item, where a user can type in a quantity -...

java.lang.NoClassDefFoundError: org/opencv/core/Core - Java Servlet + OpenCV

java,opencv,servlets
I am trying to use opencv 2.4.9. in a Java Servlet with NetBeans, i have two files - the first one is a Servlet java file Login.java which is called by index.html , and the second one is CamCap.java a java file with all the opencv imports but this file...

How does servlet container process this http request?

java,jsp,servlets
I have created a Dynamic Web Project using Eclipse for the first time to work with servlet and jsp. Below is the servlet code, package com.example.tutorial; import java.io.IOException; import java.io.PrintWriter; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; public class ServletExample extends HttpServlet { private static final long serialVersionUID =...

html form action not working when using eclipse

java,eclipse,jsp,servlets
I am new to JSP and Java Servlet. I was going through this tutorial by Java Brains. In this tutorial get and post method is handled. I wrote my html code under web-content. </head> <body> <form action="http://localhost:8080/SimpleServletProject/hello" method="post"> <input name="userName" /> <input type="submit" /> </form> </body> Following is the hello.java...

Intellij web application on tomcat server shows http://localhost:8080/index.jsp instead of http://localhost:8080/myapp/index.jsp

java,jsp,tomcat,servlets,intellij-idea
I'm following a tutorial on udemy. In the tutorial he is using eclipse. But i'm following the course with intellij. Every thing works fine but one thing i keep noticing is that when he runs the servlets or jsp pages it is always shows the project name before the servlet(http://localhost:8080/myapp/index.jsp)....

How to change jsp loop element with jQuery ajax?

java,jquery,jsp,servlets,foreach
I receive list of feeds from servlets like this: <c:forEach items="${feedList}" var="feed"> <tr> <td><input readonly="readonly" id="feedId" value="<c:out value="${feed.id}" />" /></td> <td id="feed-name"><c:out value="${feed.name}" /></td> <td><a href="FeedController?action=delete&id=<c:out value="${feed.id}"/>">Delete</a> </td> <td><a href="FeedItemController?action=feedItemListAsc&id=<c:out...

Trying to setup tomcat to use servlets

java,tomcat,servlets,invokerequired
I'm following instructions found in Java All in one for Dummies 3rd edition I downloaded tomcat and followed all the steps for setting it up, step 6 says. "Modify the web.xml file to enable the invoker servlet" It says to find the lines of code for the invoker and then...

How do I password protect an HTTP Get Request on my Apache Tomcat server?

java,apache,http,tomcat,servlets
I want to send a user some data only if they correctly supply the username and password in the header of their HTTP request. I tried doing this via the HttpServletReqest login() method, but it hasn't worked. this is my server's doGet method: protected void doGet(HttpServletRequest request, HttpServletResponse response) throws...

How to open a new page when button is clicked on

java,html,jsp,servlets,web-applications
The question is vague so allow me to clarify. I am developing a web app locally on eclipse and using Servlets, JSP, and an html document to design a web page. I have a home page which has two buttons, signup and login. I have one file, called index.jsp, which...

Requested Resource is not available error

java,jsp,servlets,twitter4j
I'm trying to build a twitter search using jsp, servlet, Tomcat-6.0.43 and eclipse and getting HTTP Status 404 error. Can anyone please check where am I going wrong. My Code: first.jsp: <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html;...

How to Get The Parameters Name From The Http request

java,servlets
I want To Get The Parameters Name From My Http request, Please Give me the Solution, Thanks In advance

Problems with select form population in JSP

java,jsp,servlets,jstl
I want to pass List object to html select. The problem is, nothing appends to html select. Here is a Obiekt class: package test; public class Obiekt { private String nazwa; private String adres; private String dyscyplina; private int idObiekt; private int idTermin; public String getNazwa() { return nazwa; }...

Why paging query does not work

java,jsp,java-ee,servlets,jdbc
The main function of this program is to write a page displays the contents of the database and can achieve Pagination When you first visit the page can display the contents of the database,But when you click on the link below when the page is not able to properly display...

Read uploaded Data from servlet line by line. and Store it on server side or servlet? [duplicate]

java,servlets
This question already has an answer here: How to upload files to server using JSP/Servlet? 9 answers Read uploaded Data from servlet line by line. and Store it on server side or servlet ? i am Using HTMl and Servlet can any body help me on this . Thanks...

Refresh a Servlet by another Servlet

java,servlets,iframe,refresh
I have to create a little webshop for a school-project, but entered in to a problem during the process by updating/refreshing the Servlets. Description: I created an index.html file which includes two servlets via iframes, the left side for Navigation-Servlet and on the right the Controller-Servlet does something to show...

JSP form sending data including files in servlet

java,jsp,servlets,post,get
I am tryig to send some data from jsp form to a servlet. All my data are type="text" except from one that is type="file". I know that if i want to send the data to my servlet, i have to use request.getParameter(...). (My data) In order not to be null...

Can we create a non parameterized constructor in servlet?

java,servlets,constructor
What I know till now: Instance of Servlet is first created by container via reflection and no argument constructor gets used. Then parameterized init method gets called. Also it is suggested that we should not create a constructor in servlet class as it is of no use. And I agree...

SSL Handshake in Java Servlet (HttpsURLConnection)

java,servlets,ssl
I have a java web application that requires a servlet to open a connection with a url that returns some data in the form of JSON back to the servlet for processing. Traditionally this was done using an HttpURLConnection and everything worked as planned. Now, we have added as self-signed...

How to return zip from bytearray on Servlet [duplicate]

java,servlets,stream
This question already has an answer here: How to create a zip file in Java 5 answers working again with Java EE. In example On servlet I have byte[] fileContent ---->(file.txt) I try to add it to zip file set servlet as response.setContentType("Content-type: text/zip"); response.setHeader("Content-Disposition", "attachment; filename=mytest.zip"); // List...

Sending text file to client through Spring MVC web application

java,spring,jsp,spring-mvc,servlets
After doing some research online on the subject I currently managed to get things working with this code: @RequestMapping(value = "/report040Generated", method = RequestMethod.GET) public String index(Model model, HttpServletResponse response, HttpServletRequest request) throws IOException { String myString = "Hello"; response.setContentType("text/plain"); response.setHeader("Content-Disposition","attachment;filename=myFile.txt"); ServletOutputStream out = response.getOutputStream(); out.println(myString); out.flush(); out.close(); return...

CORS Request Error Tomcat 7 & Java Servlet

java,tomcat,servlets
I somehow can't get this to work. I have a Java Servlet running on a Tomcat 7 Server (running on localhost:8080) and I want to make a PUT-Request from a different Webservice (running on localhost:80). I have added the CORS-Accept-Header in the Servlet-Code as well as in the Tomcat Configuration,...

Servlet path is not included in

jsp,url,servlets,jstl
I have a simple Java Webapp (eg. test) containing two different SpringMVC application. My web.xml maps them as: <servlet-mapping> <servlet-name>web</servlet-name> <url-pattern>/web/*</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>restful</servlet-name> <url-pattern>/restful/*</url-pattern> </servlet-mapping> Inside the web part I'm using "classic" libraries, such as JSTL core. I don't understand how to avoid JSTL c:url tag ignoring the URL...

Struts exclude pattern with spring

java,spring,spring-mvc,servlets,struts2
I did a lot of homework before coming here to the experts , appreciate any pointers on my question I need to run a merged (not integrated) app that was basically combined version of struts2 and Spring and some base servlets. Was able to get the combined war file up...

Store sensitive using Java Servlet API

java,servlets
I have web app which is running on Java Servlet web container,specifically on IBM WebSphere.My question is: whether there is the recommended way (as part of Java Servlet API) to store a sensitive data, like user password for example. I can write my own solution from scratch at any time,just...

How are JSP/Servlet's executed in a Java-Capable webserver? [closed]

java,jsp,tomcat,java-ee,servlets
I'm playing with writing a Java-capable webserver. How do you get from your WAR/JSP to executable Java code? I've figured at this point FCGI is not available(I do have a client impl). What kind of mechanisms or specs are here? Are there any standards?

HttpServletResponse - writing to resonse writer vs outputstream

java,servlets
When adding to some content to HttpServletResponse in java I can either get the response writer and append: httpResponse.getWriter().append("Some Content"); Or I can add content to the output-stream: ServletOutputStream servletOut = httpResponse.getOutputStream(); servletOut.write(someByteArray); Is the only difference between the two is that the first gets strings/char-sequences and the second gets...

`null` result from request in servlets

java,jsp,servlets
I am new in servlets- I am filling text in form but value in request is null- In login page- <body> <form action=""> <input type="text" name="uname"> <input type="text" name="pwd"> <a href="display.jsp">link</a> </form> </body> In DisplayPage- <body> Display: <% String uname=(String)request.getParameter("uname"); String upass=(String)request.getParameter("pwd"); out.println(uname+" - "+upass); Enumeration<String> enumeration = request.getParameterNames(); boolean...

How to do request mapping with form action?

spring,spring-mvc,servlets
I want to map a form action with controller class but the mapping doesn't found for the action.

Get JSP output within Servlet in AEM

java,jsp,servlets,cq5,aem
In CQ, we need to process jsp within servlet then combine the result with other results we get from server before writing back to browser. The following code is almost what we need, except that it writes the result back to browser after processing jsp. RequestDispatcher dispatcher = request.getRequestDispatcher(resource); dispatcher.forward(request,...

shall I use Spring framework for a performance-critical proxy application? [closed]

java,spring,authentication,servlets
I've created a servlet (Tomcat) application which has these functions: It performs HTTP Basic Authentication. It connects to a user and role database. It works as "security facade" for some geodata servers behind It forwards requests after doing some authorization tests In case the response contains XML data, it performs...

I have a pdf from which I have to extract data and show but I am getting this exception, I'm not being able to figure out what is this Exception is?

java,exception,servlets,itext,pdf-reader
I have this pdf file to extract data from, but the problem is when I'm running this piece of code as a simple java program, it works like a charm but when I tried this code on JSP servlet it gave out this exception and I'm not being able to...

How to use button instead input, style input?

css,forms,jsp,servlets,post
My form: <form method="POST" action="AController"> <div class="userInput"> <table class="userInput"> <tr> <td><input type="text" id="username" name="login"></td> </tr> <tr> <td><input type="submit" id="submitRegInput" name="reg" value="Submit"></td> </tr> </table> </div> </form> I'm trying to style <input type="submit" id="submitRegInput" name="reg" value="Submit"> like this: #submitRegInput { background: no-repeat...

Javascript time differs from Java time

java,javascript,servlets,time
i'm running a JavaServlet and as JavascriptApp on the same machine. The servlet outputs the current time: @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { ServletOutputStream os = resp.getOutputStream(); os.print("" + System.currentTimeMillis()); } The JS Gets the time: $.get("UserdataServlet", function(data) { console.log("dy " + data); console.log("my "...

I am trying to load my servlet in the browser and it gives me this error

java,html,xml,web-services,servlets
This is the error I see when I try to compile my code — am I passing the URL incorectly? I wanted to learn from this sample code to display my servlet in the browser. HTTP Status 404 - /Lesson41/ type Status report message /Lesson41/ description The requested resource is...

How to read an internal file in a web project

java,servlets,war,web-deployment,dom4j
All, Forgive me I am still learning the Java development right row. Say we have the structure of web project like below. The src and config is under the Java Resources folder of web project. src ... |- a.b.c.package |-test.java ... config |-1.xml |-2.xml ... configfolder |-1.properties |-2.properties testfolder |-test.properties...

HTTP Status 500 - java.lang.LinkageError - Servlets

java,jsp,maven,servlets,web.xml
I'm trying to configure a simple page with JSP and getting an error. My web.xml is: <?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" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0"> <display-name>ERPWep-calendar</display-name> <servlet> <servlet-name>calendar</servlet-name>...

Is there a way to get the Base URL from an Application-scoped bean in JSF?

jsf,servlets,jsf-2
In my JSF Facelets pages I know I can just use #{request.requestURL} To get the full URL to build exportable links and the like. However I have an @ApplicationScoped bean where I need the base URL (i.e. "http://dnsname/app") for the purposes of reports and other data. Is there a standard...