Nick Verma

Greenhorn
+ Follow
since Oct 27, 2004
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Nick Verma

Hello

I have two drop down boxes and depending on the value selected the appropriate jsp page should be loaded. I am wrong somewhere. Please let me know where I am wrong.
<HTML>
<BODY>
<form method = "post" action = "servers.jsp">
<h3>SUPER-1</h3><br/>
<select name="superbapi1">
<option name="server1" value = "temp1" />
<option name="server1" value = "temp2" />
<input type = "submit" value = "Submit" />
</select>
<h3>SUPER-2</h3><br/>
<select name="superbapi2">
<option name="server2" value = "temp1" />
<option name="server2" value = "temp2" />
<input type = "submit" value = "Submit" />
</select>
</form>
<%
String name1 = request.getParameter("server1");
String name2 = request.getParameter("server2");
if(name1="temp1"){
%>
<jsp:forward page = "status_sb1.jsp?server=temp1"%>
<%
}
%>

<%
if(name1="temp2"){
%>
<jsp:forward page = "status_sb1.jsp?server=temp2" %>
<%
}
%>
<%
if(name2="temp1"){
%>
<jsp:forward page = "status_sb2.jsp?server=temp1" %>
<%
}
%>
<%
if(name2="temp2"){
%>
<jsp:forward page = "status_sb2.jsp?server=temp2" %>
<%
}
%>
</BODY>
</HTML>

Thanks for your help.
19 years ago
JSP
Hello People
I am trying to build a centralized logging server that would be logging from various applications. Now the problem where I am stuck is how to filter the logs to send details according to the specific applications. Any suggestions?

I think I will need to use perl scripting. Is there any other way....using Java.

Thanks
I am trying to run an example of log4j SimpleSocketServer to accept logging from remote clients. The properties file that I am using is:

log4j.rootLogger=DEBUG, x
log4j.appender.x=org.apache.log4j.net.SocketAppender
log4j.appender.x.RemoteHost=localhost
log4j.appender.x.Port=4445
log4j.appender.x.LocationInfo=true
log4j.appender.x.layout=org.apache.log4j.PatternLayout
log4j.appender.x.layout.ConversionPattern=[%d{MMM dd HH:mm:ss}] %-5p (%F:%L) - %m%n

While running I get the following error.

C:\logging-log4j-1.2.9\examples\chapter1>java org.apache.log4j.net.SimpleSocketS
erver 4445 log4j.properties
log4j:ERROR Could not connect to remote log4j server at [localhost]. We will try
again later.
java.net.ConnectException: Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(Unknown Source)
at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at org.apache.log4j.net.SocketAppender.connect(SocketAppender.java:195)
at org.apache.log4j.net.SocketAppender.activateOptions(SocketAppender.ja
va:152)
at org.apache.log4j.config.PropertySetter.activate(PropertySetter.java:2
47)
at org.apache.log4j.config.PropertySetter.setProperties(PropertySetter.j
ava:123)
at org.apache.log4j.config.PropertySetter.setProperties(PropertySetter.j
ava:87)
at org.apache.log4j.PropertyConfigurator.parseAppender(PropertyConfigura
tor.java:645)
at org.apache.log4j.PropertyConfigurator.parseCategory(PropertyConfigura
tor.java:603)
at org.apache.log4j.PropertyConfigurator.configureRootCategory(PropertyC
onfigurator.java:500)
at org.apache.log4j.PropertyConfigurator.doConfigure(PropertyConfigurato
r.java:406)
at org.apache.log4j.PropertyConfigurator.doConfigure(PropertyConfigurato
r.java:307)
at org.apache.log4j.PropertyConfigurator.configure(PropertyConfigurator.
java:315)
at org.apache.log4j.net.SimpleSocketServer.init(SimpleSocketServer.java:
84)
at org.apache.log4j.net.SimpleSocketServer.main(SimpleSocketServer.java:
44)


Please advise where is the problem.
Thanks
Thanks a lot for your suggestions. Hope it helps me in learning the ins and outs of the language.
You can check the ACM programming contest website. They emphasize on algorithms. But the questions are tough.
19 years ago
Perhaps this will provide a clear picture

package banking;

public class Customer{

private String firstName;
private String lastName;
private Account account;

Account accounts[];
int numberOfAccounts = 0;

public Customer(){
accounts = new Account[100];
}

public void addAccount(Account a){
System.out.println(a);
//account = a;
//accounts[numberOfAccounts++] = account;
//accounts[numberOfAccounts++] = new Account(a);
//accounts[numberOfAccounts++] = a;
}

public int getNumOfAccounts(){
return numberOfAccounts;
}

public Account getAccount(int ac){
return accounts[ac];
}


public Customer(String f,String l){
firstName = f;
lastName = l;
}

public String getFirstName(){
return firstName;
}

public String getLastName(){
return lastName;
}

public Account getAccount(){
return account;
}

public void setAccount(Account acct){
account = acct;
}

};

and

/*
* This class creates the program to test the banking classes.
* It creates a set of customers, with a few accounts each,
* and generates a report of current account balances.
*/

import banking.*;
import java.text.NumberFormat;

public class TestBanking {

public static void main(String[] args) {
NumberFormat currency_format = NumberFormat.getCurrencyInstance();
Bank bank = new Bank();
Customer customer;

// Create several customers and their accounts
bank.addCustomer("Jane", "Simms");
customer = bank.getCustomer(0);
customer.addAccount(new SavingsAccount(500.00, 0.05));
customer.addAccount(new CheckingAccount(200.00, 400.00));

bank.addCustomer("Owen", "Bryant");
customer = bank.getCustomer(1);
customer.addAccount(new CheckingAccount(200.00));

bank.addCustomer("Tim", "Soley");
customer = bank.getCustomer(2);
customer.addAccount(new SavingsAccount(1500.00, 0.05));
customer.addAccount(new CheckingAccount(200.00));

bank.addCustomer("Maria", "Soley");
customer = bank.getCustomer(3);
// Maria and Tim have a shared checking account
customer.addAccount(bank.getCustomer(2).getAccount(1));
customer.addAccount(new SavingsAccount(150.00, 0.05));

// Generate a report
19 years ago
I tried to print the value of "ac" being received by addaccount and found out that the following set of code gives the error

bank.addCustomer("Maria", "Soley");
customer = bank.getCustomer(3);
// Maria and Tim have a shared checking account
customer.addAccount(bank.getCustomer(2).getAccount(1));
customer.addAccount(new SavingsAccount(150.00, 0.05));.............in TestBanking.java
and

public Account getAccount(int ac){
return accounts[ac];
}

and there is another overloaded method

public Account getAccount(){
return account;
} in the same class.
......in Customer.java as the new error being thrown is
G:\Java\SCJP\mod06\exercise2>java TestBanking
banking.SavingsAccount@3fbdb0
banking.CheckingAccount@3e86d0
banking.CheckingAccount@50169
banking.SavingsAccount@1fcc69
banking.CheckingAccount@253498
Exception in thread "main" java.lang.NullPointerException
at banking.Customer.getAccount(Customer.java:30)
at TestBanking.main(TestBanking.java:35)
19 years ago
I have a bank class, one customer class, one accounts class having two derived classes: Savingaccount and Checking account in a package banking. and then there is a TestBanking class outside this package. Everything works fine until the insertion of this code:

Account accounts[];
int numberOfAccounts = 0;

public Customer(){
accounts = new Account[100];
}

public void addAccount(Account a){
//account = a;
//accounts[numberOfAccounts++] = account;
//accounts[numberOfAccounts++] = new Account(a);
accounts[numberOfAccounts++] = a;
}

public int getNumOfAccounts(){
return numberOfAccounts;
}

public Account getAccount(int ac){
return accounts[ac];
}

After this segment of code is inserted compilation is fine but at run time the following error is thrown.

G:\Java\SCJP\mod06\exercise2>java TestBanking
Exception in thread "main" java.lang.NullPointerException
at banking.Customer.addAccount(Customer.java:21)
at TestBanking.main(TestBanking.java:20)

Please advise. The whole code is too big to be pasted here......but in case it is needed I can paste that.
Thanks in advance
19 years ago
Hello People,
I am trying to find out an IDE which just provides simple text editor feature and an option to debug like setting breakpoints, stepping into, stepping over so that I can know how the control flow is taking place and what my program is doing. What I see till now is heavy IDE with lots of features which don't help in learning the language.
So please advice.
Thanks