File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes how to use the request objects while calling a java method in jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "how to use the request objects while calling a java method in jsp" Watch "how to use the request objects while calling a java method in jsp" New topic
Author

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

Sagar Bh
Greenhorn

Joined: Oct 08, 2012
Posts: 4
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

Joined: Jan 28, 2008
Posts: 5575

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

Joined: Jan 28, 2008
Posts: 5575

Welcome to JavaRanch Sagar Bh :)
Sagar Bh
Greenhorn

Joined: Oct 08, 2012
Posts: 4
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

Joined: Mar 10, 2012
Posts: 149

Struts 1 or Struts 2 ?


hate Professionalism . Join the http://2014.hack.lu/index.php/Main_Page
Arun Giridhar
Ranch Hand

Joined: Mar 10, 2012
Posts: 149

Sagar Bh wrote:
I need to do this from the scriptlet itself.


Why ?
Sagar Bh
Greenhorn

Joined: Oct 08, 2012
Posts: 4
struts 1
shiva pandey
Greenhorn

Joined: Jan 24, 2011
Posts: 10
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

Joined: Jan 28, 2008
Posts: 5575

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

Joined: Oct 08, 2012
Posts: 4
have tried it. This does not work. not even throw any error.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to use the request objects while calling a java method in jsp