tags:

views:

97

answers:

2

I created one jsp and html file.My constraint is to i created one button inside html,if i ckick the button then control goes to jsp program. coding as follows

HTML

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt;
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<form action="/home/crimson/workspace/popject/samplejsp/sample.jsp" method=get>
    <input type =submit value="submit">
    </form>
</body>
</html>

JSP CODING

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt;
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
      This is jsp program
</body>
</html>

But it shows the following Error:

404 ERROR The requested resource (/sample.jsp) is not available.

Directory Structure

samplejsp
 ---WENCONTENT
       --- WEBINF
              ---sample.html
              ---sample.jsp
+1  A: 

404 simply means "Not Found".

Either the URL is wrong (note: case sensitive!), or the resource is not there where you think it is.

That's all. Just verify the URL and/or verify if the resource is there where you'd expect it to be.

Update: I see that you attempted to post a directory structure, but failed because you didn't formatted it nor paid attention to the formatting after update (in the future please do so, I've fixed it for you). You placed both sample.html and sample.jsp in /WEB-INF folder. This way they are not public accessible without calling through a servlet. But that does not explain how you get that far to sample.html.

At any way, public files should not be placed inside /WEB-INF folder and your form action should point to an URL, not to a local disk file system path. Also see the comments.

BalusC
ya i checked but it shows the above error ,Is there any error in the program
Yes, either the URL is wrong, or the resource is actually not there. The error message does not lie.
BalusC
ok,i accept the error message not lie,Ya error occurred in URL i understood that also,I selected the the jsp file and copied the URL from Properties,Then why it shows the error,How to solve this?
Hint: the URL should be an URL, not a disk file system path. If `sample.html` is at `http://localhost:8080/samplejsp/sample.html` then the `sample.jsp` is obviously at `http://localhost:8080/samplejsp/sample.jsp`. Thus the `<form action>` should be `http://localhost:8080/samplejsp/sample.jsp` or better just `sample.jsp`. In your case, this should do: `<form action="sample.jsp">`.
BalusC
A: 

It's mostly related to your directory structure or packaging.
Can you please add your directory structure?

Similar to below -

src 
|-html\
|-jsp\

Perhaps this should do it

<form action="sample.jsp" method=get>
      <input type =submit value="submit">
</form>

Edit - WEB-INF does not allow direct access to JSP.

Padmarag
ok i add my directory structure
I tried the above action method,but it shows the same error
See the updated code above.
Padmarag
sorry i tried this coding also but it shows the same error
Quick fix - Move the HTML and JSP file from WEB-INF folder and run.
Padmarag
Move means where i placed these two file,how to edit WEB_INf
I mean move both the files from WEB-INF to some other folder.
Padmarag