Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to use the request objects while calling a java method in jsp

 
Sagar Bh
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am trying to run the following code in my jsp. I have imported the java classes in my jsp page. but i am not able to pass the request objects in the java method when I am calling the java method from within the scriptlets.
Can anyone please help me as soon as possible.
Below is a code snippet from my jsp.

<%
String startDttm = AbcUtil.getCurrentDateTimeXXXFormat();
String endDttm = AbcUtil.getCurrentDateTimeXXXFormat();
com.demo.AbcdDemoDao abcdDemoDao= new AbcdDemoDao ();%>
<%
abcdDemoDao.insertLogonData("LOGON", "", %>
"<%= request.getRemoteHost() %>"
<%, %>
"<%= request.getServerName() %>"
<%, startDttm, endDttm,"User", %>
"<%= request.getUserPrincipal().getName() %>"
<%,"FAILURE") ;
}
%>

I am getting no error when trying with hard coded strings instead of the request objects.
This code is giving syntax error.
Any help is appreciated. Thanks
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
javax.servlet.http.HttpServletRequest object is available in service method(between <% %>) in the name of *request* implicitly.
so just pass the reference request to that java method.

*I suggest you to visit servlet first do there your business and then go to jsp

Note: WhyNotUseScriptlets
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch Sagar Bh :)
 
Sagar Bh
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Seetharaman,

Thank you for the quick response.
Can you please elaborate abit more. I am working on a struts application and do not have a servlet. I need to do this from the scriptlet itself.
Please let me know how can i correct this peice of code.
Many Thanks
 
Arun Giridhar
Ranch Hand
Posts: 181
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Struts 1 or Struts 2 ?
 
Arun Giridhar
Ranch Hand
Posts: 181
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sagar Bh wrote:
I need to do this from the scriptlet itself.


Why ?
 
Sagar Bh
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
struts 1
 
shiva pandey
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's not a good approach you are using .But if still you want your code to run just remove expression tag and "" quotes while putting them into method.
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sagar Bh wrote: I am working on a struts application and do not have a servlet.

it has master servet(in struts 1.x) and it invoke action depends on *path* similar to url-mapping.
you can put your code in action- designed for your business logic.

and struts has its own custom tag similar to JSTL to replace scriptlet
 
Sagar Bh
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
have tried it. This does not work. not even throw any error.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic