Http status 401 This request requires HTTP authentication (). in tomcat 6

I have developed a web application if i run the application in tomcat 6 it asks for username and password but after 3 attempsts it shows <?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/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd” id=”WebApp_ID” version=”2.5″> <display-name>LoginRemote</display-name> <welcome-file-list> <welcome-file>index.html</welcome-file> <welcome-file>index.htm</welcome-file> <welcome-file>index.jsp</welcome-file> <welcome-file>default.html</welcome-file> <welcome-file>default.htm</welcome-file> <welcome-file>default.jsp</welcome-file> </welcome-file-list> <servlet> <description></description> <display-name>remoteSample</display-name> <servlet-name>remoteSample</servlet-name> <servlet-class>com.src.remoteSample</servlet-class> </servlet> <servlet-mapping> <servlet-name>remoteSample</servlet-name> <url-pattern>/remoteSample</url-pattern> … Read more

How to specify the default error page in web.xml?

On Servlet 3.0 or newer you could just specify <web-app …> <error-page> <location>/general-error.html</location> </error-page> </web-app> But as you’re still on Servlet 2.5, there’s no other way than specifying every common HTTP error individually. You need to figure which HTTP errors the enduser could possibly face. On a barebones webapp with for example the usage of … Read more

KeyPressed event in java

Depending on where you want to trap the “enter” key, you could use an ActionListener (on such components such as text components or buttons) or attach a key binding to you component public class MyPanel extends JPanel { public MyPanel() { InputMap im = getInputMap(WHEN_FOCUSED); ActionMap am = getActionMap(); im.put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), “onEnter”); am.put(“onEnter”, new AbstractAction() { @Override public void … Read more

How to define a relative path in java

Here is the structure of my project : I need to read config.properties inside MyClass.java. I tried to do so with a relative path as follows : // Code called from MyClass.java File f1 = new File(“..\\..\\..\\config.properties”); String path = f1.getPath(); prop.load(new FileInputStream(path)); This gives me the following error : ..\..\..\config.properties (The system cannot find … Read more

ShoppingCart.Java Program Assignment

I am working on an assignment and I have run into a few problems. Here is the Assignment Question and what I’ve done so far and my question. Complete ShoppingCart.java as follows: Declare and instantiate a variable cart to be an empty ArrayList that can hold Product objects. Remember to import ArrayList. Comments in the … Read more

How to implement Java “Scanner” in C++?

You seem to be using Scanner to read one integer at a time from the standard input stream. This is easily accomplished with the extraction operator, operator>>. Replace this code: Scanner scan = new Scanner(System.in); int number=0; int loopValue = scan.nextInt(); //System.out.println(“print: “+loopValue); for(int i=0;i<loopValue;i++) { number = scan.nextInt(); // System.out.println(“print: “+number); With this: int number=0; int loopvalue=0; … Read more

Could not find or load main class with a Jar File

I’m trying to load a jar using @echo off java -jar Test.jar pause With the manifest of Manifest-Version: 1.0 Main-Class: classes.TestClass In the Jar directory, I can clearly see a classes\TestClass file when I extract it. Edit: classes.TestClass does have a public static void main(String[] args). Package Deceleration in classes.TestClass is package classes; But I … Read more

Map of maps – how to keep the inner maps as maps?

Here is the updated code that seems to work, you need to type the map of maps as <String, Object> since mp isn’t a string you can’t do <Object, String>. import java.util.HashMap; import java.util.Iterator; import java.util.Map; import java.util.Set; import java.util.ArrayList; public class MapExample { public static void main(String[] args) { Map<Object,String> mp=new HashMap<Object, String>(); // … Read more