Forums de discussion

how to take the parameters from jsp to servlet..

Bhaskar Koppuravuri, modifié il y a 13 années.

how to take the parameters from jsp to servlet..

New Member Publications: 18 Date d'inscription: 19/01/11 Publications récentes
hi all,

i am developing a sample portlet i.e it has to transfer parameters form the jsp to servlet.

in this process i placed my jsp file in view.jsp and the java file in src folder and now i stucked where to keep my web.xml file..

can any one help to work out this portlet....
thumbnail
Anil Sunkari, modifié il y a 13 années.

RE: how to take the parameters from jsp to servlet..

Expert Publications: 427 Date d'inscription: 12/08/09 Publications récentes
Hello Bhaskar,

I don't know by using which development you are creating portlets.Whatever it is i suggest you to go for plugins for basic understanding for all your queries.

Regards,
Anil Sunkari
Bhaskar Koppuravuri, modifié il y a 13 années.

RE: how to take the parameters from jsp to servlet..

New Member Publications: 18 Date d'inscription: 19/01/11 Publications récentes
hi Anil Sunkari,

I am using the plugin sdk only for developing my portlet.what i done is first i created a portlet in the view.jsp i placed my jsp code which contains the form action and in the src folder i placed my servlet java program.after the "ant build" it is getting success msg.but it is not going to the java program..

for your clarity information i am pasting the code here

-------view.jsp--------------------

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form action="first" method="GET">
Name:<input type="text" name="name">
<br>
<br>
Age:<input type="text" name="age">
<br>
<br>
<br>
<input type="submit" value="check voting eligiblity">
</form>

</body>
</html>


--------------my servlet program---------------------

package bhaskar;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class votersrv extends HttpServlet
{
public void doGet(HttpServletRequest req,HttpServletResponse res)throws ServletException,IOException
{
PrintWriter pw=res.getWriter();
res.setContentType("text/html");
String name=req.getParameter("name");
String age=req.getParameter("age");
int age1=Integer.parseInt(age);
String msg=null;
if(age1<18)
{
msg=name+"u r not eligible to vote";
pw.println("<font color='red'>"+msg+"</font>");

}
else
{
msg=name+"u r eligible to vote";
pw.println("</font color='green'>"+msg+"</font>");
}
pw.println("<br><a href='input.html'>go</a>");
pw.close();
}
}

-----------web.xml----------------


<servlet>
<servlet-name>voter</servlet-name>
<servlet-class>bhaskar.votersrv</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>voter</servlet-name>
<url-pattern>/first</url-pattern>
</servlet-mapping>




now it is not creating the web.xml directly we need to place it some ware i need that place..the parameters should be transfer to the servlet program.... can any one help me....
thumbnail
Raju OO7, modifié il y a 13 années.

RE: how to take the parameters from jsp to servlet..

Regular Member Publications: 239 Date d'inscription: 27/04/10 Publications récentes
can u share ur portlet class and portlet.xml file?


liferay is providing different methods to get parameter values from request.. its very easy to use..

eg:
String userName = ParamUtil.getString(request, "userName");
Long userId = ParamUtil.getLong(request, "userId");
Bhaskar Koppuravuri, modifié il y a 13 années.

RE: how to take the parameters from jsp to servlet..

New Member Publications: 18 Date d'inscription: 19/01/11 Publications récentes
this is my portlet.xml file


xsi:schemaLocation="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd"
>
<portlet>
<portlet-name>abc</portlet-name>
<display-name>abc</display-name>
<portlet-class>com.liferay.util.bridges.mvc.MVCPortlet</portlet-class>
<init-param>
<name>view-jsp</name>
<value>/view.jsp</value>
</init-param>
<expiration-cache>0</expiration-cache>
<supports>
<mime-type>text/html</mime-type>
</supports>
<portlet-info>
<title>abc</title>
<short-title>abc</short-title>
<keywords>abc</keywords>
</portlet-info>
<security-role-ref>
<role-name>administrator</role-name>
</security-role-ref>
<security-role-ref>
<role-name>guest</role-name>
</security-role-ref>
<security-role-ref>
<role-name>power-user</role-name>
</security-role-ref>
<security-role-ref>
<role-name>user</role-name>
</security-role-ref>
</portlet>
</portlet-app>


AND my java class file is

package bhaskar;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class votersrv extends HttpServlet
{
public void doGet(HttpServletRequest req,HttpServletResponse res)throws ServletException,IOException
{
PrintWriter pw=res.getWriter();
res.setContentType("text/html");
String name=req.getParameter("name");
String age=req.getParameter("age");
int age1=Integer.parseInt(age);
String msg=null;
if(age1<18)
{
msg=name+"u r not eligible to vote";
pw.println("<font color='red'>"+msg+"</font>");

}
else
{
msg=name+"u r eligible to vote";
pw.println("</font color='green'>"+msg+"</font>");
}
pw.println("<br><a href='input.html'>go</a>");
pw.close();
}
}



please provide solution.....waiting for solution!
thumbnail
Raju OO7, modifié il y a 13 années.

RE: how to take the parameters from jsp to servlet..

Regular Member Publications: 239 Date d'inscription: 27/04/10 Publications récentes
i dont know y u r extending httpServlet Class.. instead of tht u can extend GenericPortlet Class and try it..

also change ur <portlet-class>com.liferay.util.bridges.mvc.MVCPortlet</portlet-class> with ur custom calss
Bhaskar Koppuravuri, modifié il y a 13 années.

RE: how to take the parameters from jsp to servlet..

New Member Publications: 18 Date d'inscription: 19/01/11 Publications récentes
hi Raju OO7


sorry i dont know how to work on the liferay api..

can you please try this portlet working and send me back i will go through it.
thumbnail
Raju OO7, modifié il y a 13 années.

RE: how to take the parameters from jsp to servlet..

Regular Member Publications: 239 Date d'inscription: 27/04/10 Publications récentes
i didnt get any attachments frm u..
Bhaskar Koppuravuri, modifié il y a 13 années.

RE: how to take the parameters from jsp to servlet..

New Member Publications: 18 Date d'inscription: 19/01/11 Publications récentes
In this i am attaching the portlet....


Work it once and send the working portlet....

Pièces jointes:

thumbnail
Raju OO7, modifié il y a 13 années.

RE: how to take the parameters from jsp to servlet..

Regular Member Publications: 239 Date d'inscription: 27/04/10 Publications récentes
chk this..

Pièces jointes:

Bhaskar Koppuravuri, modifié il y a 13 années.

RE: how to take the parameters from jsp to servlet..

New Member Publications: 18 Date d'inscription: 19/01/11 Publications récentes
Thanks for providing the solution..

can i know how to develop the portlet code?
thumbnail
Raju OO7, modifié il y a 13 années.

RE: how to take the parameters from jsp to servlet..

Regular Member Publications: 239 Date d'inscription: 27/04/10 Publications récentes
read JSR168 then JSR286 and finally Liferay Docs and resources
Bhaskar Koppuravuri, modifié il y a 13 années.

RE: how to take the parameters from jsp to servlet..

New Member Publications: 18 Date d'inscription: 19/01/11 Publications récentes
hi raju


i have to navigate the view.jsp file to some other jsp file withe the help of the form tag how i can write the tag..can any one help
thumbnail
Dhandapani S, modifié il y a 13 années.

RE: how to take the parameters from jsp to servlet..

Regular Member Publications: 176 Date d'inscription: 24/03/09 Publications récentes
Hi Bhaskar,

This may help u for getting the details with elaborate...

For Developing Portlets :
http://www.liferay.com/community/wiki/-/wiki/Main/Developing+Portlets+in+Liferay+IDE


Regards

Dhandapani S