Connecting to Servlet from a JSP page

i have a jsp page at \BioSS\WebRoot\jsp and it has a form with action ="SetNewStatus"

where SetNewStatus is servlet name. that is placed at \BioSS\WebRoot\WEB-INF\classes\com\bss\servlet

when i call the servlet by clicking the submit button i get an error Resouce not found.

plz help me to do this i am unable to set the exact path

thanks in advance

[380 byte] By [12345789a] at [2007-11-26 17:04:10]
# 1

> form with action ="SetNewStatus"

> where SetNewStatus is servlet name. that is placed at

> \BioSS\WebRoot\WEB-INF\classes\com\bss\servlet

> when i call the servlet by clicking the submit button

> i get an error Resouce not found.

Hi there,

Have you mapped com.bss.servlet.SetNewStatus with url /SetNewStatus under \BioSS\WebRoot\WEB-INF\web.xml if not use the following snippent and add it under <web-app> </web-app> node

<servlet>

<servlet-name>SetNewStatus</servlet-name>

<servlet-class>com.bss.servlet.SetNewStatus</servlet-class>

</servlet>

<servlet-mapping>

<servlet-name>SetNewStatus</servlet-name>

<url-pattern>/SetNewStatus</url-pattern>

</servlet-mapping>

and try to make GET request to the servlet.

you might have to restart Web-server after doing this.Check it out with it.If doesn't work still just try to revert back to us.

I'm sure someone out here wud alwys help.

& please avoid reposting

http://forum.java.sun.com/thread.jspa?threadID=224500&messageID=9474726#9474726

REGARDS,

RaHuL

RahulSharnaa at 2007-7-8 23:31:57 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
yap i also have map it in web.xml file exactly the same way as u mentioned ...any other clue...
12345789a at 2007-7-8 23:31:57 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

could you just explain the entire senario to me of what message ru getting there....

what happens when you are trying with an encoded URL say

http://<hostname>:<applnport>/<webapp>/<servlet_name>?<req_pram1>=<value1>&<req_pram2>=<value2> .......

Just test whether you are getting an error code of 404 if no then it has to something with your code

& one more thing can U give me you application.getRealPath() value try to get that using scriptlets in on the JSP pages side.

& try to paste your servlet code tooo i mean the entire servlet code just for reference.

REGARDS,

RaHuL

RahulSharnaa at 2007-7-8 23:31:57 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4

i am developing an application that have a jsp page like this

<%@ page language="java"%>

<%@ page import="com.bss.bean.SessionUserInfo" %>

<%@ page import="java.util.Vector"%>

<%@ page import="com.bss.bean.Device" %>

<%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean"%>

<%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html"%>

<%@ taglib uri="http://jakarta.apache.org/struts/tags-logic" prefix="logic"%>

<html:html locale="true">

<head>

<title>BSS - Device Status Settings</title>

<meta http-equiv="pragma" content="no-cache">

<meta http-equiv="cache-control" content="no-cache">

<meta http-equiv="expires" content="0">

<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">

<!--<link rel="stylesheet" type="text/css" href="styles.css">-->

<STYLE type="text/CSS">

<!--

TD.HEADING {bgcolor:#ACBBCC ;font-family:Arial;

font-size:12pt; font-style:bold; text-indent:3ex }

TD.NORMAL {font-family:Arial; font-size:11pt ; text-indent:5ex }

TR.NORMAL {font-family:Arial; font-size:12pt ; text-indent:3ex; align:center }

TD.FOOTER {font-family:Arial; font-size:10pt }

-->

</STYLE>

</head>

<jsp:useBean id="htmlUtil" class="com.bss.utilities.HtmlUtil" scope="session"></jsp:useBean>

<body bgcolor="#ACBCCC">

<table height="100%" width = "100%" border=0 >

<tr height="20%">

<td>

<%=htmlUtil.getHeader((SessionUserInfo)session.getAttribute(SessionUserInfo.class.getName()))%>

</td>

</tr>

<tr ><td height="70%">

<table width=100% height = "100%" border="1" align="center">

<tr>

<td width=70%>

<form action="SetNewStatus" method="POST">

<% Vector devices = (Vector)session.getAttribute("devices");

String names[] = new String[8];

String status[] = new String[8];

for(int i = 0; i< devices.size(); i++){

names = ((Device)devices.elementAt(i)).getDevice();

status = ((Device)devices.elementAt(i)).getStatus();

}

%>

<table align="center" border="1">

<TR class="NORMAL" >

<th><bean:message key="device.name" /></th>

<th><bean:message key="device.current.status"/></th>

<th><bean:message key="device.status" /></th>

</TR>

<tr class = "NORMAL">

<td><%=names[0]%></td>

<td><%=status[0]%></td>

<TD>

<input type="radio" name="names0"

><% if (status[0].equalsIgnoreCase("On")){%> CHECKED<%}%>/>On

<input type="radio" name="names0" value="off"

><% if (status[1].equalsIgnoreCase("Off")){%> CHECKED<%}%>/>Off

</TD>

</tr>

<TR class = "NORMAL">

<td><%=names[1]%></td>

<td><%=status[1]%></td>

<TD>

<input type="radio" name="names1"

><% if (status[1].equalsIgnoreCase("On")){%> CHECKED<%}%>/>On

<input type="radio" name="names1" value="off"

><% if (status[1].equalsIgnoreCase("Off")){%> CHECKED<%}%>/>Off

</TD>

</tr>

<TR class = "NORMAL">

<td><%=names[2]%></td>

<td><%=status[2]%></td>

<TD>

<input type="radio" name="names2"

><% if (status[2].equalsIgnoreCase("On")){%> CHECKED<%}%>/>On

<input type="radio" name="names2" value="off"

><% if (status[2].equalsIgnoreCase("Off")){%> CHECKED<%}%>/>Off

</TD>

</tr>

<TR class = "NORMAL">

<td><%=names[3]%></td>

<td><%=status[3]%></td>

<TD>

<input type="radio" name="names3"

><% if (status[3].equalsIgnoreCase("On")){%> CHECKED<%}%>/>On

<input type="radio" name="names3" value="off"

><% if (status[3].equalsIgnoreCase("Off")){%> CHECKED<%}%>/>Off

</TD>

</tr>

<TR class = "NORMAL">

<td><%=names[4]%></td>

<td><%=status[4]%></td>

<TD>

<input type="radio" name="names4"

><% if (status[4].equalsIgnoreCase("On")){%> CHECKED<%}%>/>On

<input type="radio" name="names4" value="off"

><% if (status[4].equalsIgnoreCase("Off")){%> CHECKED<%}%>/>Off

</TD>

</tr>

<TR class = "NORMAL">

<td><%=names[5]%></td>

<td><%=status[5]%></td>

<TD>

<input type="radio" name="names5"

><% if (status[5].equalsIgnoreCase("On")){%> CHECKED<%}%>/>On

<input type="radio" name="names5" value="off"

><% if (status[5].equalsIgnoreCase("Off")){%> CHECKED<%}%>/>Off

</TD>

</tr>

<TR class = "NORMAL">

<td><%=names[6]%></td>

<td><%=status[6]%></td>

<TD>

<input type="radio" name="names6"

><% if (status[6].equalsIgnoreCase("On")){%> CHECKED<%}%>/>On

<input type="radio" name="names6" value="off"

><% if (status[6].equalsIgnoreCase("Off")){%> CHECKED<%}%>/>Off

</TD>

</tr>

<TR class = "NORMAL">

<td><%=names[7]%></td>

<td><%=status[7]%></td>

<TD>

<input type="radio" name="names7"

><% if (status[7].equalsIgnoreCase("On")){%> CHECKED<%}%>/>On

<input type="radio" name="names7" value="off"

><% if (status[7].equalsIgnoreCase("Off")){%> CHECKED<%}%>/>Off

</TD>

</tr>

</table>

<center>

<input type = "submit" name="submit" value="Submit" tabindex="2"/>

<input type = "button" name="submit" value = "Cancel" tabindex="3"/>

<input type = "reset" name="submit" value = "Reset" tabindex="4"/>

</center>

</form></td>

</tr>

</table>

</td></tr>

<TR height="10%">

<td ><%=htmlUtil.getFooter()%></td>

</TR>

</table>

</body>

</html:html>

besides other woring only check form tag and its action attribute that calls the servlet setNewStatus that is

/**

*

*/

package com.bss.servlet;

import java.io.IOException;

import java.util.Enumeration;

import java.util.Vector;

import javax.servlet.ServletException;

import javax.servlet.http.HttpServlet;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

import javax.servlet.http.HttpSession;

public class SetNewStatus extends HttpServlet

{

private static final long serialVersionUID = 1L;

public void init() throws ServletException

{

}

public void doGet(HttpServletRequest request, HttpServletResponse response)

throws ServletException, IOException {

doPost(request, response);

}

public void doPost(HttpServletRequest request, HttpServletResponse response)

throws ServletException, IOException {

String redirectUrl = null;

String param = request.getParameter("sumbit");

if(param.equalsIgnoreCase("submit")){

HttpSession session = request.getSession(true);

Enumeration names = request.getParameterNames();

while(names.hasMoreElements()){

System.out.println(names.nextElement().toString());

}

//Vector devices = new Vector();

redirectUrl = "/BioSS/jsp/admin.jsp";

}

else if (param.equalsIgnoreCase("cancel")){

redirectUrl = "/BioSS/jsp/admin.jsp";

}

else if (param.equalsIgnoreCase("reset")){

redirectUrl = "/BioSS/jsp/deviceStatus.jsp";

}

response.sendRedirect(redirectUrl);

}

public void destroy()

{

super.destroy();

}

}

it does not do the actual work but here i print out all the parameter name and values of radio type input tag that are further used for database insertion etc ...

this jsp page is called from another jsp page then this jsp page calls the servlet for further processing....

i think its enough wat u asked.

12345789a at 2007-7-8 23:31:57 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5

<form action="SetNewStatus" method="POST">

i asked u to try with

<form action="SetNewStatus" method="GET">

>>try to make GET request to the servlet

and please make use of a common method instead of calling doPost() from do get.say requestProcessor(HttpServletRequest,HttpServletResponse)

have u done that if yes i seriously think it has to some with your web.xml

btb can i know the reason why u are using struts-bean and other tlds in this page ?

RahulSharnaa at 2007-7-8 23:31:57 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...