[英]how to pass values from jsp to java class
My Jsp page 我的Jsp页面
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@page contentType="application/xml" trimDirectiveWhitespaces="true" %>
<%@ page import="com.raos.kookooivr.CallStatusValues" %>
<c:choose>
<c:when test='${(param.event == "Conference" || param.event == "Hangup" || param.event == "Disconnect") && requestScope.state == "conferenceStarted"}'>
<%
String session_id = request.getParameter("sid");
out.print(CallStatusValues.getsessionid(session_id));
String called_no = request.getParameter("cid");
out.print(CallStatusValues.getcalledno(called_no));
String actualtime = request.getParameter("total_call_duration");
out.print(CallStatusValues.getactualtime(actualtime));
String start_time = request.getParameter("start_time");
out.print(CallStatusValues.getstarttime(start_time));
String end_time = request.getParameter("time");
out.print(CallStatusValues.getendtime(end_time));
%>
</c:when>
</c:choose>
My Java Class 我的Java课
package com.raos.kookooivr;
public class CallStatusValues
{
public static String getsessionid(String session_id)
{
System.out.println(session_id);
return session_id;
}
public static String getcalledno(String called_no)
{
System.out.println(called_no);
return called_no;
}
public static String getactualtime(String actualtime)
{
System.out.println(actualtime);
return actualtime;
}
public static String getstarttime(String start_time)
{
System.out.println(start_time);
return start_time;
}
public static String getendtime(String end_time)
{
System.out.println(end_time);
return end_time;
}
}
I am getting 500 Error. 我收到500错误。
I am trying to pass the values of " String session_id = request.getParameter("sid");
" to my java class and trying to print the session id 我试图将“ String session_id = request.getParameter("sid");
“的值传递给我的java类,并尝试打印会话ID
public static String getsessionid(String session_id)
{
System.out.println(session_id);
return session_id;
}
I need help to get the values from jsp to be printed using my java class. 我需要帮助来从jsp获取要使用我的java类进行打印的值。 Example my sid is 123456. Then, that session id should be passed from my jsp file to my java class. 例如,我的sid是123456。然后,该会话ID应该从我的jsp文件传递到我的java类。
I'm afraid there are multiple problems with your code. 恐怕您的代码有多个问题。
I suggest you download a simple working J2EE JSP servlet project and analyse how it works. 我建议您下载一个简单的可运行的J2EE JSP servlet项目并分析其工作方式。 Then start to modify it to suit your requirements. 然后开始修改它以适合您的要求。 Something like http://crunchify.com/servlet-tutorial-getting-starting-with-jsp-servlet-example should get you started. 像http://crunchify.com/servlet-tutorial-getting-starting-with-jsp-servlet-example之类的东西会帮助您入门。
Unsure that you are doing what you want to do. 不确定您在做什么。
Here is what actually happens : 这是实际发生的情况:
BTW using a class with static methods that way from a JSP, is at least uncommon... It could make sense if you need to be able to to complex computations inside the JSP, but in that case, you'd better use a servlet to do the processing, store result in request attribute and forward to the servlet. BTW在JSP中使用带有静态方法的类至少是不常见的……如果您需要能够在JSP内部进行复杂的计算,这可能是有道理的,但是在这种情况下,最好使用servlet进行处理,将结果存储在request属性中并转发到servlet。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.