Tripti Ag

Ranch Hand
+ Follow
since Jul 03, 2009
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
1
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Tripti Ag

Sender1 Code:-

import jade.core.Agent;
import jade.core.AID;
import jade.core.behaviours.CyclicBehaviour;
import jade.lang.acl.ACLMessage;
import java.io.*;

public class Sender1 extends Agent
{
protected void setup()
{
addBehaviour(new CyclicBehaviour(this)
{
public void action()
{
ACLMessage msg= receive();
if (msg!=null)
{System.out.println("\n\n\n I am Agent 1 ");
System.out.println( "Answer Received from -" + msg.getSender().getLocalName()+"- <- " + msg.getContent() );
System.out.println("Thank you");
}
else {
System.out.println(" Chatting Agents ");
System.out.println(" note ---> To stop Chatting write 'stop' in agent1 query");
System.out.println(" I am Agent1 "+myAgent.getLocalName());}
try{
ACLMessage msg1 = new ACLMessage(ACLMessage.INFORM);
msg1.addReceiver( new AID( "Tr2", AID.ISLOCALNAME) );
msg1.setLanguage("English");
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);

System.out.print("My query :-> ");

String st=br.readLine();

if (!st.equals("stop"))
{
msg1.setContent( st );
send(msg1);
}
else
{ doDelete();
System.exit(0);
} }catch(IOException e)
{ }

block();
}
});

}
}


Receiver Code:-

import jade.core.Agent;
import jade.core.AID;
import jade.core.behaviours.CyclicBehaviour;
import jade.lang.acl.ACLMessage;
import java.io.*;

public class Receiver1 extends Agent
{
protected void setup()
{
addBehaviour(new CyclicBehaviour(this)
{ boolean val1=false;
public void action()
{
ACLMessage msg=receive();
if(msg!=null)
{ try{
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
System.out.println(" \n\n\n I am agent2"+ myAgent.getLocalName());
System.out.println("Query received from agent1 -" +msg.getSender().getLocalName()+" -:"+ msg.getContent());


System.out.print(" \n\n Agent 2 Replying :-> ");
ACLMessage reply = msg.createReply();
reply.setPerformative( ACLMessage.INFORM );
String st="";
st=br.readLine();
reply.setContent(st);
send(reply);
block();

}catch(IOException e)
{}
}

}




});
}
}

I want to run sender and receiver code on two different machines. What I did is that on sender machine, I executed the following command:-
c:\>java jade.Boot -gui senderagent:Sender;

and on receiver machine, I used the following command:-
c:\>java jade.Boot -host hostname (which is agrawal) -container receiveragent:Receiver1;

At home, I created wireless adhoc network on two laptops and connected them.

But I am getting errors on both machines. On Sender machine: Remote object is unreachable and on Receiver machine I am getting IMTPException. After googling I came to know the possible cause of error is either port no. 1099 already occupied or requirement to pass address of receiver while creating AID object.
3 years ago
I have downloaded a free template folder from a website and renamed folder as WebTemplate. Now I want to create a small website using java and want to use the downloaded template folder in each web page. How I can do this?
I went to tools menu in netbeans ide-> selected templates-> add. But I am not able to proceed further since add allows me to add specific file and not the entire folder.
I know, that's why I posted it too. Earlier filename was input_jstl.jsp. Thanks.
4 years ago
JSP
I changed filename to Test.jsp and now it is working properly
4 years ago
JSP
/input_jstl.jsp (line: 42, column: 12) According to TLD or attribute directive in tag file, attribute value does not accept any expressions

Line 42 is
Name: <c:out value="${param.username}" /><br>
4 years ago
JSP
<%@ page contentType="text/html" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<head>
<title>User Info Entry Form </title>
</head>
<body>
<form action="input_jstl.jsp" method="post">
<table>
<tr>
<td> Name: </td>
<td><input type="text" name="username"> </td>
</tr>
<tr>
<td> Birth Date: </td>
<td><input type="text" name="birthdate"></td>
<td> (use format yyyy-mm-dd) </td>
</tr>
<tr>
<td>Email Address: </td>
<td><input type="text" name="email"></td>
<td> (use format name@company.com) </td>
</tr>
<tr>
<td> Gender: </td>
<td><input type="radio" name="gender" value="m" checked>Male<br>
<input type="radio" name="gender" value="f">female </td>
</tr>
<tr>
<td>Favorite Foods: </td>
<td><input type="checkbox" name="food" value="pi">Pizza <br>
<input type="checkbox" name="food" value="pa">Pasta <br>
<input type="checkbox" name="food" value="ch">Chinese<br>
</td>
</tr>
<tr>
<td colspan=2><input type="submit" value="Submit"></td>
</tr>
</table>
</form>

<br><br><h3> You have entered the following data: </h3> <br><br>
Name: <c:out value="${param.username}" /><br>
Birth Date: <c:out value="${param.birthdate}" /><br>
Email Address: <c:out value="${param.email}" /><br>
Gender: <c:out value="${param.gender}" /> <br>
Favorite Food: <c:forEach items="${paramValues.food}" var="current">
<c:out value="${current}" />  
</c:forEach>
</body>
</html>

Still getting the same error.
4 years ago
JSP
Thanks K. Tsang!! Got it.
4 years ago
JSP
Thanks Bear Bibeault.
Problem has been resolved but some understanding is needed.
When you told me to put bean inside a package. Then I created subfolders under webapps as MyJSP3\com\Test\Person.java. Problem didn't solve by this.
But when I created development environment as follows:
c:\>MyApp
|____classes
| |____com
| |____Test(must be test)
| |_____Person.class
|____src
| |_____Person.java
|
|____etc
| |____web.xml
|____web
|____PersonJsp.java
Problem resolved. Don't know how??

4 years ago
JSP
Bear Bibeault: I want to know why we need to keep source file in a package.
Also I was referring Head First Servlets, I want to know why development environment and deployment environment have been separated in that book.
4 years ago
JSP
I come to know bean must reside in a package, so under WEB-INF\classes, I have created subfolders com\test
and put .class file under it.

Changed jsp code is as follows:

<%@ page import="com.Test.Person" %>
<html>
<head></head>
<body>
<jsp:useBean id="person" class="com.Test.Person" scope="request" />
<jsp:setProperty name="person" property="name" value="Tripti" />
This JSP Page is created by:<jsp:getProperty name="person" property="name" />

</body>
</html>

Now getting error:

HTTP Status 500 - Servlet.init() for servlet ServletJSP3 threw exception

type Exception report

message Servlet.init() for servlet ServletJSP3 threw exception

description The server encountered an internal error that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: Servlet.init() for servlet ServletJSP3 threw exception
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041)
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603)
org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
java.lang.Thread.run(Unknown Source)

root cause

java.lang.NoClassDefFoundError: com/Test/Person (wrong name: Person)
java.lang.ClassLoader.defineClass1(Native Method)
java.lang.ClassLoader.defineClass(Unknown Source)
java.security.SecureClassLoader.defineClass(Unknown Source)
org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:2918)
org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:1174)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1669)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1547)
org.apache.jasper.compiler.Generator$GenerateVisitor.visit(Generator.java:1217)
org.apache.jasper.compiler.Node$UseBean.accept(Node.java:1181)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2375)
org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2427)
org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2433)
org.apache.jasper.compiler.Node$Root.accept(Node.java:474)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2375)
org.apache.jasper.compiler.Generator.generate(Generator.java:3517)
org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:250)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:373)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:353)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:340)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:646)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:357)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.init(JspServlet.java:138)
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041)
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603)
org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
java.lang.Thread.run(Unknown Source)

4 years ago
JSP
Directory Structure:
C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\MyJSP3\WEB-INF\classes\Person.class
Under WEB-INF, I have web.xml.
C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\MyJSP3\PersonJsp


JSP Code:
<%@ page import="Person" %>
<html>
<head></head>
<body>
<jsp:useBean id="person" class="Person" scope="request" />
<jsp:setProperty name="person" property="name" value="Tripti" />
This JSP Page is created by:<jsp:getProperty name="person" property="name" />

</body>
</html>

--->Person.java (resides in default package; I know not a good practice at all)

import java.io.Serializable;

public class Person implements Serializable
{
private String name;
private String email;
private String phone;

public Person()
{
name="";
email="";
phone="";
}

public void setName(String n)
{
name=n;
}
public String getName()
{
return name;
}
public void setEmail(String e)
{
email=e;
}
public String getEmail()
{
return email;
}
public void setPhone(String p)
{
phone=p;
}
public String getPhone()
{
return phone;
}
}

---->web.xml
<web-app>
<servlet>
<servlet-name>ServletJSP3 </servlet-name>
<jsp-file>/PersonJsp.jsp</jsp-file>
</servlet>

<servlet-mapping>
<servlet-name>ServletJSP3 </servlet-name>
<url-pattern>/PersonJsp.jsp</url-pattern>
</servlet-mapping>

</web-app>


--->Error:
HTTP Status 500 - Unable to compile class for JSP:

type Exception report

message Unable to compile class for JSP:

description The server encountered an internal error that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: Unable to compile class for JSP:

An error occurred at line: [14] in the generated java file: [C:\Program Files\Apache Software Foundation\Tomcat 7.0\work\Catalina\localhost\MyJSP3\org\apache\jsp\PersonJsp_jsp.java]
The import Person cannot be resolved

An error occurred at line: 5 in the jsp file: /PersonJsp.jsp
Person cannot be resolved to a type
2: <html>
3: <head></head>
4: <body>
5: <jsp:useBean id="person" class="Person" scope="request" />
6: <jsp:setProperty name="person" property="name" value="Tripti" />
7: This JSP Page is created by:<jsp:getProperty name="person" property="name" />
8:


An error occurred at line: 5 in the jsp file: /PersonJsp.jsp
Person cannot be resolved to a type
2: <html>
3: <head></head>
4: <body>
5: <jsp:useBean id="person" class="Person" scope="request" />
6: <jsp:setProperty name="person" property="name" value="Tripti" />
7: This JSP Page is created by:<jsp:getProperty name="person" property="name" />
8:


An error occurred at line: 5 in the jsp file: /PersonJsp.jsp
Person cannot be resolved to a type
2: <html>
3: <head></head>
4: <body>
5: <jsp:useBean id="person" class="Person" scope="request" />
6: <jsp:setProperty name="person" property="name" value="Tripti" />
7: This JSP Page is created by:<jsp:getProperty name="person" property="name" />
8:


An error occurred at line: 7 in the jsp file: /PersonJsp.jsp
Person cannot be resolved to a type
4: <body>
5: <jsp:useBean id="person" class="Person" scope="request" />
6: <jsp:setProperty name="person" property="name" value="Tripti" />
7: This JSP Page is created by:<jsp:getProperty name="person" property="name" />
8:
9: </body>
10: </html>


An error occurred at line: 7 in the jsp file: /PersonJsp.jsp
Person cannot be resolved to a type
4: <body>
5: <jsp:useBean id="person" class="Person" scope="request" />
6: <jsp:setProperty name="person" property="name" value="Tripti" />
7: This JSP Page is created by:<jsp:getProperty name="person" property="name" />
8:
9: </body>
10: </html>


Stacktrace:
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:103)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:366)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:468)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:378)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:353)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:340)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:646)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:357)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.init(JspServlet.java:138)
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041)
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603)
org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
java.lang.Thread.run(Unknown Source)

4 years ago
JSP
Problem has been resolved. I removed "/" from the path to image. Thanks!!
4 years ago
JSP
Thanks for giving so much stress on my mistake. I will remember this mistake throughout my life :-).
Now I have created a separate jsp file which is as follows
<html>
<head></head>
<body>
<img src="\google.jpg"><br>
</body>
</html>
I have saved the file in MyJSP folder. Now problem is image is not visible . I think its related to path.
4 years ago
JSP
I have developed a very small JSP code to use include directive

<%@ page contentType="text/html" %>
<%@ include file="/google.jpg" %>

<html>
<head>
<title> JSP Page </title>
</head>

<body>
<br><br><br><br><br><br><br><br>
<h1> Explore the world of Google search </h1>
</body>
</html>


My directory structure is as follows:
c:\program files\Apache Software foundation\tomcat 7.0\webapps\MyJSP
Inside webapps\MyJSP:
WEB-INF
|____web.xml
IncludeJSP.jsp
google.jpg

Web.xml is as follows:
<web-app>
<servlet>
<servlet-name> jsp </servlet-name>
<jsp-file> /IncludeJSP.jsp </jsp-file>
</servlet>

<servlet-mapping>
<servlet-name> jsp1 </servlet-name>
<url-pattern>/IncludeJSP.jsp</url-pattern>
</servlet-mapping>

</web-app>

When I remove include directive, code is running properly. After including directive, I am getting error as:
HTTP Status 500 - /IncludeJSP.jsp (line: 2, column: 1) Invalid byte 1 of 1-byte UTF-8 sequence.
type Exception report

message /IncludeJSP.jsp (line: 2, column: 1) Invalid byte 1 of 1-byte UTF-8 sequence.

description The server encountered an internal error that prevented it from fulfilling this request.

exception
org.apache.jasper.JasperException: /IncludeJSP.jsp (line: 2, column: 1) Invalid byte 1 of 1-byte UTF-8 sequence.
org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:42)
org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:443)
org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:89)
org.apache.jasper.compiler.Parser.processIncludeDirective(Parser.java:324)
org.apache.jasper.compiler.Parser.parseIncludeDirective(Parser.java:357)
org.apache.jasper.compiler.Parser.parseDirective(Parser.java:467)
org.apache.jasper.compiler.Parser.parseFileDirectives(Parser.java:1779)
org.apache.jasper.compiler.Parser.parse(Parser.java:135)
org.apache.jasper.compiler.ParserController.doParse(ParserController.java:242)
org.apache.jasper.compiler.ParserController.parseDirectives(ParserController.java:119)
org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:193)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:373)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:353)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:340)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:646)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:357)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)


4 years ago
JSP