H Singh

Ranch Hand
+ Follow
since Apr 03, 2005
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 H Singh

I am trying to publish a simple web app. Below are the steps:

-Run on Server
-Select Websphere 5.1 - Express Server (Next)
-Screen says : Specify the settings for target server - Host Name : localhost
-Popup - WEbsphere server warning - ensure variable WAS_HOME_V51 is set to the correct Websphere installation dierctory on the remote agent controller (OK)

- (nexyt screen) Webspeher server settings - specify settings for the target server

Questions : I just want to run it on local server - there is no option where i can select local test enviornment.....

I will appreciate any help .

Thanks
14 years ago
What happens when we declare a type, but not a class ?

JSP
<jsp:useBean id="person" type="foo.person" scope="page" >

Result if the person attribute already exists in "page" scope:

It works perfectly

Result if the person attribute does not exist in the "page" scope:

javax.servlet.ServletException: bean person not found within scope


I am not able to understand - what will make the person attribue available in the page scope (for the above JSP) ?

Thanks
Hello Sergio:

Can you please explain why would
requestScope[integer] return 0 but
requestScope["integer"] or requestScope['integer'] return 3

Thanks
Thanks Kapil...dont know what i was thinking when i posted the question...

one more question ....

i am trying to use setProperty , below is my jsp :

result.jsp:

<html><body>

<jsp:useBean id="person" class="com.example.Person" scope="page" >
Person created by: <jsp:setProperty name="person" property="name" value="Fred" />
</jsp:useBean>

</body></html>

and PersonServlet.java

public class PersonServlet extends HttpServlet{

public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException{
doPost(request,response);
}

public void doPost(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException{

Person p = new Person();

//p.setName("Evan");
//request.setAttribute("person",p);

RequestDispatcher view = request.getRequestDispatcher("result.jsp");
view.forward(request,response);
}
}

It says "the property value will be set only if a new bean is created. If an existing bean with that scope and id are found, the body of the tag will never run, so property won't be reset from your JSP code "

So i commented

//p.setName("Evan");
//request.setAttribute("person",p);

still i do not get Fred in the output. Thanks
I want to use getProperty to print both name and value. Please take a look at the code below :-

Person.java:

public class Person{

private String name;
private int value;

public void setName(String name){
this.name = name;
}

public String getName(){
return name;
}

public void setValue(int value){
this.value = value;
}

public int getValue(){
return value;
}
}

PersonServlet.java:

public class PersonServlet extends HttpServlet{

public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException{
doPost(request,response);
}

public void doPost(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException{

Person p = new Person();

p.setName("Evan");
p.setValue(1);

request.setAttribute("person",p);

RequestDispatcher view = request.getRequestDispatcher("result.jsp");
view.forward(request,response);
}
}

result.jsp:

<html><body>
<jsp:useBean id="person" class="com.example.Person" scope="request" />
Person created by: <jsp:getProperty name="person" property="name" />
</body></html>

What will it take to print Evan and 1 ? Thanks
It defines the mapping between the name client uses ( /org.apache.jserv.JServ ) and the actual servlet class (org.apache.tomcat.servlets.StatusServlet )

<servlet-name> tag : You will use the name (status in your case) defined here within other parts of the DD

So when a request comes in,
1.the container finds <url-pattern> that has /org.apache.jserv.JServ.
2.then container gets the <servlet-name> ( status )
3.container looks in the <servlet> tag for <servlet-name> ( status )
4. then it uses the actual <servlet-class>

hope this helps
I tried again but same results.

I have Tomcat 5.0.28 installed.

code:

package com.example;

import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import com.example.*;

public class MusicServlet extends HttpServlet{

public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException{

String[] favoriteMusic = {"Zero 7","Tahiti 80","BT"};
request.setAttribute("musicList",favoriteMusic);

RequestDispatcher view = request.getRequestDispatcher("result.jsp");
view.forward(request,response);
}
}

web.xml

<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">;

<web-app>

<servlet>
<servlet-name>MusicServlet1</servlet-name>
<servlet-class>com.example.MusicServlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>MusicServlet1</servlet-name>
<url-pattern>/MusicServlet</url-pattern>
</servlet-mapping>

</web-app>


result.jsp

<%@ page isELIgnored="false" %>
<html><body>
Music is : ${musicList["0"]}
</body></html>

With <%@ page isELIgnored="false" %> in result.jsp, i get correct results.

Without <%@ page isELIgnored="false" %> in result.jsp, i get
Music is : ${musicList["0"]}

I don't know if there is any other global setting, which is causing EL to get ignored.
Hello Anand and Jamed
..thanks for the prompt reply..

i specified
<%@ page isELIgnored ="false" %> in my result.jsp and it worked.

I have Tomcat 5 installed ( Tomcat version 5 implements the Servlet 2.4 and JavaServer Pages 2.0 specifications )

Also, i read :
The default mode for JSP pages delivered with a Servlet 2.4 descriptor is to evaluate EL expressions.

And i do not have <el-ignored> true </el-ignored>..in my web.xml
Hey guys:

I am trying HFSJ example- page 371

I get : Music is : ${musicList["0"]} in the result instead of : Zero 7

Code is below:

package com.example;

import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import com.example.*;

public class MusicServlet extends HttpServlet{

public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException{

String[] favoriteMusic = {"Zero 7","Tahiti 80","BT"};
request.setAttribute("musicList",favoriteMusic);

RequestDispatcher view = request.getRequestDispatcher("result.jsp");
view.forward(request,response);
}
}

result.jsp :

<html><body>
Music is : ${musicList["0"]}
</body></html>

What did i miss?

Thanks
HS
Thanks a lot Anand....it worked
Hey Guys:

I am trying to implement " Going straight from the request to the JSP without going through a servlet" - page 358 of HFSJ

Below is my code:

form.html

<html><body>
<form action="TestBean.jsp">
name: <input type="text" name="userName">
<input type="submit">
</form>
</body></html>

TestBean.jsp

<html><body>
<jsp:useBean id="person" class="com.example.Person" />
<jsp:setProperty name="person" property="name" param="userName" />
</body></html>

Person.java

package com.example;

public class Person{

private String name;

public void setName(String name){
this.name = name;
}

public String getName(){
return name;
}
}

I get the following error :

The value for the useBean class attribute com.example.Person is invalid.
org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:39)

i do not understand the use of id="person" here. Can someone tell me how to use param attribute correctly
I get the following error:

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

An error occurred at line: 2 in the jsp file: /result.jsp
Generated servlet error:
C:\Tomcat5\work\Catalina\localhost\Persons\org\apache\jsp\result_jsp.java:43: cannot resolve symbol
symbol : class Person
location: class org.apache.jsp.result_jsp
Person person = null;

Code for PersonServlet, Person and result.jsp is below:

import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;


public class PersonServlet extends HttpServlet{

public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException{
doPost(request,response);
}

public void doPost(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException{

Person p = new Person();

p.setName("Evan");
request.setAttribute("person",p);

RequestDispatcher view = request.getRequestDispatcher("result.jsp");
view.forward(request,response);
}
}

public class Person{

private String name;

public void setName(String name){
this.name = name;
}

public String getName(){
return name;
}
}

<html><body>
<jsp:useBean id="person" class="Person" scope="request" />
Person created: <jsp:getProperty name="person" property="name" />
</body></html>

PersonServlet and Person class files are under:
webapps\Persons\WEB-INF\classes directory

and result.jsp is at webapp level ( \Persons\result.jsp)

I have set up my classpath as well:

C:\Tomcat5\webapps\Persons\WEB-INF\classes;C:\Tomcat5\common\lib\servlet-api.jar;

Any help will be appreciated.
[ June 14, 2005: Message edited by: HS ]