Servlets :: Getting Path Of The Base URL?

Feb 5, 2014

I have a data.json in my J2EE web app.I need to load it either from local path when unit testing or from url when the server starts up.

so I've set it to get the local path by default and what I'm trying to do is that it is is running on a server, I'd like to change the path to a url.

Here is my code:

public String getUrlBase(HttpServletRequest request) {
URL requestUrl;
try {
requestUrl = new URL(request.getRequestURL().toString());
String portString = requestUrl.getPort() == -1 ? "" : ":" + requestUrl.getPort();
return requestUrl.getProtocol() + "://" + requestUrl.getHost() + portString + request.getContextPath() + "/";
} catch (MalformedURLException e) {
e.printStackTrace();
}
return null;
}

which works fine. The only issue is that I had to place this in the login page. Is there a way I can only set the path to the base url upon server start up?

View Replies


ADVERTISEMENT

For Loop To Convert Any Number Entered To Base 10 With Any Base Provided

Oct 9, 2014

So i'm writing a for loop to convert any number entered to base 10 with any base provided as well. My code does not work because I need a way to reverse the code order, so the new number is printed correctly with the given base. My code so far:

public static void main (String[] args) {
Scanner kb = new Scanner (System.in);
System.out.print("Enter a number :: ");
int numOriginal = kb.nextInt();
System.out.print("Enter a base :: ");
int base = kb.nextInt();

[Code] .....

newBase has a problem with how it calculates the new number, looking for correct newBase code for conversion?

View Replies View Related

Program To Convert A Base 10 Integer To Any Base 2 - 16

May 5, 2013

I am writing a program to convert a base 10 integer to any base 2-16. Here are the terms:"The method is to convert the decimal value the user selected into whatever base the user selected and print the converted value one place value at a time by using an index into an array of characters 0-9 amd A-F that is initialized to contain those characters.In the method you will find the largest place value (i.e. power of the base) that will divide into the decimal number.

Then you can set up a loop that will operate from that power down to and including the 0th power to determine how many times each place value goes into the decimal number. Using the loop counter, index into the character array to print the character that corresponds to the quotient number and then subtract the product of the place value and the quotient from the decimal number. With the power (loop index) decreased, repeat until you finish the 0th place value. Here's what I have so far:

import java.io.*;
import java.util.Scanner;
public class ConvertIt
{//start program
public static void main(String[] args)
{//start main
Scanner input = new Scanner(System.in);
System.out.println("Enter a positive integer from 0 to 10000.");
int number = input.nextInt();

[code]...

View Replies View Related

Java Base N To Base M Conversion

Jul 18, 2014

We were asked to do a program in java that could convert Base n to Base m. and im really having trouble with it.

View Replies View Related

Servlets :: Context Path After Forward

Mar 23, 2015

I have normal adress which works, like

localhost/contextPath/foo

In URL rewrite filter I forward that call like

((HttpServletRequest) req).getRequestDispatcher(".....foo1.jsp").forward(req, res);

And it gets there. On that page (foo1.jsp) I have link to original href

<a href="localhost/contextPath/foo">click.</a>

When I click that, in url rewrite filter I get:

String url = ((HttpServletRequest)req).getRequestURL().toString();// http://contextPath/foo/contextPath/foo
String uri = ((HttpServletRequest)req).getRequestURI().toString();// /contextPath/foo/contextPath/foo

which is bad address. How to handle that and why it happens ?

View Replies View Related

Servlets :: Relative Or Absolute Path

Feb 14, 2014

Is /graphics/image.png a relative path or absolute path?

View Replies View Related

Servlets :: Unable To Get Path Of File When Upload Files In Server After Browsing Folders

Jun 30, 2014

I have a code that uploads files in server after browsing folders and files then get the paths of files but I have a problem in getting the paths

List items = upload.parseRequest(request);
Iterator iterator = items.iterator();
while (iterator.hasNext()) {
FileItem item = (FileItem) iterator.next();
if (!item.isFormField())
{ fileName = item.getName();
root = getServletContext().getRealPath("/");
path = new File(root + "/uploads");

[Code]...

list1 must has paths that I want but I do not get the paths of upload files

View Replies View Related

Servlets :: How To Upload File To Dropbox With Only File Name (without Path) Using Java

Dec 1, 2014

In my web application i want to upload file to drop-box. I am getting file name from browser.Is it possible to upload file to drop-box with only file name.

Below the drop-box upload code with java.

File inputFile = new File("New Text Document.txt");
System.out.println("inputFile.getAbsoluteFile(): " + inputFile);
FileInputStream inputStream = new FileInputStream(inputFile);
try {
DbxEntry.File uploadedFile = client.uploadFile("/magnum-opus.txt",
DbxWriteMode.add(), inputFile.length(), inputStream);
System.out.println("Uploaded: " + uploadedFile.toString());
} finally {
inputStream.close();
}

In the above code the place New Text Document.txt we have to provide total path of file.

View Replies View Related

Use Relative Path In Place Of Absolute Path

Nov 7, 2014

I am copying the xml files from one folder to other folder, in the source folder, i have some files which have some content like "backing File="$IDP_ ROOT/metadata/iPAU-SP-metadata.xml" but while writing to the destination folder.i am replacing the "$IDP_ROOT" with my current working directory. The entire copying of files is for deploying into tomcat server. The copying is done only when server starts for the first time.Problem: If i change the folder name from my root path in my machine after i run the server,the entire process will be stopped because the destination folder files already contains the content which is with existed files names or folder names.

So i want to change it to relative path instead absolute path. What is the best way to do it? Please look at code below:

[ // Getting the current working directory
String currentdir = new File(".").getAbsoluteFile().getParent() + File.separator;

if(currentdir.indexOf("ControlPanel")!=-1){
rootPath=currentdir.substring(0, currentdir.indexOf("ControlPanel"));
}else{
rootPath=currentdir;

[code]....

View Replies View Related

Base Converting Program

Jan 24, 2015

The idea behind this program is that the program prompts the user to input an initial base (2-36), which checks to ensure that it is a valid int, then asks for a number to convert (which is taken as a String), then it asks which desired base the user would like to convert said number to. I have a basic program that is not complete, but allows me to do a few conversions using convertTo. I believe that I am going to have abandon this method and try mathematically converting every number. This leads me to what I can and cannot do. I am unable to use the initialBase as a condition to know what kind of number i an converting. For instance, I don't know how to make program know that if "2" is the initialBase, that that means that the String is a binary number. THAT is what I'm having problems with.

Here is my initial program that has a few things that are copied and pasted from other bits of my code in my program:

XML Code: Url...

I have broken down what I (think I) need to do here: Check to see if the input base is 2, 8, 10, 16, or 32. Hint: Put the possible bases in an array, and check the input base against the array. Check to see if the input number is valid for the base. Hint: Create a String "0123456789ABC...V" and compare each input character with the first "base" characters of the String. Check to see if the output base is 2, 8, 10, 16, or 32. Hint: Use the same possible bases array you used in step 1 to verify the input base.Check to see if the input base is equal to the output base. If so, print the input number. Perform a conversion from the input base to base 10. Perform a conversion from base 10 to the output base. You do this in 2 steps because it's easier to check each conversion separately.Output the converted number.

View Replies View Related

Base Form For Add / Edit / Delete

Sep 7, 2014

I have been developing what I intent to be a base class for several forms that will allow the user for adding / editing / deleteing records. These records could be customers, products, suppliers etc.

I have designed a basic form that has an add, edit and delete button. For the add button, I would want to clear all the values in all of the controls (textboxes, combox etc) in preperation for adding a new record.

My question is this. Is this something I should do in the base class OR should it be handled in the classes that will extend from the base class? Perhaps if the controls were datalinked to the data they will clear themselves (I haven't got that far yet so I dont know). I thought maybe I could write code in the base class that could loop through all of the controls and call this from the extended classes.

View Replies View Related

Hexadecimal Java Base Converter

Apr 28, 2015

I am writing a program that converts any base 10 number to bases 2-16. I have the code for everything up through hexadecimal conversion, for that requires the use of letters. I understand an array list may be of use however I do not understand how to use that in this code. Below is what I have so far

import java.util.*;
import java.io.*;
public class convertBase
{
public static void main(String[] args)
{
int base;
int number;
String newNum;
 
[code].....

I commented out the hexadecimal portions.How would I go about coding for letters?

View Replies View Related

How To Use Exception Handling As Base Class

Jun 17, 2014

I want to use my given code as base class

Java Code:

public static void file(String[] arg) throws IOException{
BufferedReader in;
String line;
try{
System.out.println("Reading word");
in =new BufferedReader(new FileReader("inp.txt"));

[Code] .....

View Replies View Related

Program To Change Base Of Integer Decimal

Nov 2, 2014

I know how to do this program it is just not coming to me. The whole point is to calculate and display the base (base-2 or binary, base-8 or octal and base-16 or hexadecimal) in representation of 'N'. The symbols A, B, C, D, E, F should display 10, 11, 12, 13, 14, and 15 in hexadecimal system.

import java.io.*;
import java.util.Scanner;
public class ChangeBase
{
public static void main(String[]args) {
double num;

[Code]...

View Replies View Related

Scientific Method - Compute Base Times 10 To Exponent

Feb 13, 2015

This is what I need to do: Write a method called scientific that accepts two real numbers as parameters for a base and an exponent and computes the base times 10 to the exponent, as seen in scientific notation. For example, the call of scientific(6.23, 5.0) would return 623000.0 and the call of scientific(1.9, -2.0) would return 0.019.

This is the method I have written:

public double scientific(double num1, double num2); {
double base = num1;
double exp = num2;
double scientific = base * Math.pow(10, exp);
System.out.println(scientific);
return scientific;
}

These are the following error messages I received when trying to compile the code:

Line 4
missing method body, or declare abstract
missing method body, or declare abstract
public double scientific(double num1, double num2);

[Code] .....

How to fix each error?

View Replies View Related

Java App To Open A Console Base Program And Run A Command

Jan 13, 2015

I am struggling getting my java app to open a console window on either MacOS or windows and run a command. On windows I can get the cmd.exe program to open, but it won't execute the command. On MacOS, I cannot get it to even open the terminal.

String run = "c:
s34bil.exe
elap5.exe" + in + rst + out; //in, rst, out are parameters for the relpa5.exe file.
try {
Runtime rt = Runtime.getRuntime();
rt.exec(new String[]{"cmd.exe","/c",run,"start"});
} catch (IOException ex) {
Logger.getLogger(issrsUI.class.getName()).log(Level.SEVERE, null, ex);
}

View Replies View Related

Private Var Won't Save Value Of Public Getter Function From Base C

Sep 15, 2014

I'm working on this program for a class to create objects of a commissioned employee and union employee. Everything seems to work ok, but when I run my final pay calculation, one of my getter functions will not pass the variable for the pay into a class specific variable called check. here is the code in this function.

public void finalPayCal_U() {
setweekPay();//calculates weeks pay under 40 hours, stored in getweekpay
check = getweekPay();
if(getHours() > 40){
check = check + (1.5 * (getHours() - 40) * getRateOfPay());
}
check =- Dues;
}
}

The issue lies in check = getweekPay();

I thought this was a legal move, but I can't get it to work. It doesn't come back with anything more than 0 any time I run it.

All of these functions are out of the base class, employee (this function itself lives in the derived union class)

public void setweekPay() {
if (hours <= 40) {
weekPay = hours * rateOfPay;
} else {
weekPay = 40 * rateOfPay;
}
}

When I run, this function works as it returns the value when i print it to test.

however, when I do the part that says check = getWeekPay() above, it doesn't change the check variable. The only thing I have on the check variable is the dues taken out of it at the end, so it ends up being a negative number.

I have a similar problem with the other derived class's check variable. Both classes have the same variable as private but one is check the other checkC.

View Replies View Related

Swing/AWT/SWT :: Changing Color Of Jtable Base On A Row Of Cell Value In One Column

Feb 10, 2014

My code is

Double qty = 0.0;
for ( int i = 0; i < ingTable.getRowCount(); i++){
qty = (Double) ingTable.getValueAt(i,2);
if( qty < 30.0){
ingTable.setBackground(Color.red);
} else {
ingTable.setBackground(Color.white);
}
}

View Replies View Related

Program For Class To Request User Input For Base Salary

Feb 24, 2014

I had to write a program for class to request user input for base salary, number of years worked, and total sales. Then use the data to find out the employee's paycheck when including a bonus. I have a few issues with the code, as I have one bug, then it won't calculate anything. what I'm missing?

package chapterone;
import java.util.Scanner;
public class Examplelab {
static Scanner console = new Scanner(System.in);
public static void main(String[] args){
double baseSalary;
double noOfServiceYears;
double totalSales;

[Code]....

View Replies View Related

Accessing Private Field Of Derived Object In Base Class?

Apr 1, 2013

I have this piece of code I wrote a while ago to test something. The issue is accessing a private field of Base class in Base but of a Derived object.

Here is the code:
class Base
{
private int x;
public int getX()

[Code]....

The commented code does not work but casting d to Base does.

Forgot to mention that the compilation error is that x has private access in Base.

View Replies View Related

How To Set JDK8 As PATH

May 5, 2014

My OS: Windows 7

Problem:

I've tried where javac in command prompt but it can't locate it. I need to know how to set JDK 8 as PATH.

View Replies View Related

Set Path To File In Jar App

May 12, 2014

What I do wrong when I trying to set path to file in my jar app. I have application which work with xml file. I have next project structure:

/project_root_directory
|_  /lib
|_  /resources/file.xml
|_  /src
 
So, I need to set correctly path to my jar file, because when I running it from IDE, it works nice. By default it seems:

private File file;
private StreamResult streamResult;
file = new File("resources/file.xml");
streamResult = new StreamResult(file);

And methods where I can modify the DOM structure via transformer in end of methods:

transformer.transform(source, streamResult);

So, I trying set path to file:

private URL url;
...
file = new File(url.getPath());
streamResult = new StreamResult(file);
 
But it didn't not work, because when I trying to get resource by next condition

url = getClass().getResource("resources/file.xml");
url = getClass().getResource("resources/file.xml");url = getClass().getResource(url = getClass().getResource("resources/file.xml");resources/file.xml");
url - is null
Okay..
 
I tried next solution
 
InputStream input = getClass().getResourceAsStream("resources/file.xml"); 
 
There, I got also null....
 
Also, I tried made absolute path
 
filePath = file.getAbsolutePath();
file = new File(filePath);
streamResult = new StreamResult(file);

But it also didn't work. There I got message seems like: "Can't find resource /User/user1/Desktop/program1/resources/file.xml" - but that's really absolute path to a file.
 
Also, I tried made it via System.getProperty

String filename = "file.xml";
String workingDir = System.getProperty("user.dir");
finalfile = workingDir + File.separator + "resources" + File.separator + filename;
file = new File(finalfile);

I also made unit test which completed with "green light", but in jar its wrong with message "Can't find resource /User/user1/Desktop/program1/resources/file.xm" ....

View Replies View Related

Relative Path Not Working

Sep 11, 2014

relative path not working if specified folder is outside eclipse IDE, but if i put same folder in current project it is working.

View Replies View Related

The System Cannot Find The Path Specified

Feb 25, 2015

I have the Java Development Kit downloaded in my C file and my book tells me to compile the program I need to open command windowand change the directory where the program is stored. I tried the command cd to change directory and received this message "The system cannot find the path specified."

I checked the Environment Variables on Windows 7 and the Path says: C:Program Files (x86)Javajre1.8.0_31in

This is after many tries and i still can't change directory and i keep getting the same message.

View Replies View Related

Java Path Variable

Mar 2, 2014

I have BlueJ installed on my computer and it does the job of compiling the java source code written in it. If I want to write and compile source code outside of BlueJ do I still need to download the Java SDK and set the PATH variable, even though I am apparently able to do it in BlueJ?

View Replies View Related

System Cannot Find Path Specified

Feb 24, 2015

I have the Java Development Kit downloaded in my C file and my book tells me to compile the program I need to open command windowand change the directory where the program is stored. I tried the command cd to change directory and received this message "The system cannot find the path specified." I checked the Environment Variables on Windows 7 and the Path says: C:Program Files (x86)Javajre1.8.0_31in

This is after many tries and i still can't change directory and i keep getting the same message.The book I am using to learn Java is "Java How to Program: Tenth Edition" from Paul and Harvey Deitel.

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved