• Post Reply Bookmark Topic Watch Topic
  • New Topic

html to jsp page transfer  RSS feed

 
sanket jani
Ranch Hand
Posts: 47
C++ Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello everyone
i am trying to move from html to jsp
in html it is simple code
and in jsp there is database connection .
but from html it is not going on the page of jsp
i put correct address in the form action attribute in html file
i am attaching both my files...

following is my html code :-

<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<h3>ok its running fine</h3>
<form action="/ADMIN/add_material.jsp" method="post">
<div>
<table>
<tr>
<td>
Material Name :-
</td>
<td>
<input name="materialName" type="text" >
</td>
</tr>
<tr><td>    </td></tr>
<tr>
<td>
Material Mass :-
</td>
<td>
<select name="materialMass">
<option value="kilogram">KG</option>
<option value="gram">GM</option>
<option value="miligram">MG</option>
</select>
</td>
<td>
Mass Value :-
</td>
<td>
<input type="text" name="massValue">
</td>
</tr>
<tr><td>    </td></tr>
<tr>
<td>
Material Value :-
</td>
<td>
<input name="materialValue" type="text" >
</td>
</tr>
<tr><td>    </td></tr>
<tr>
<td>

</td>
<td>
<input name="abc" type="submit" value="ADD MATERIAL" >
</td>
</tr>
</table>
</div>
</form>
</body>
</html>

following is jsp code :-

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%@page import="java.sql.*" %>
<%@page import="java.io.*" %>
<%@page import="java.sql.Connection" %>

<h3>IN THE ADD MATERIAL JSP</h3>

<%
System.out.println("yes we here");
String materialName = request.getParameter("materialName");
String materialMass = request.getParameter("materialMass");
String massValueStr = request.getParameter("massValue");
String materialValueStr = request.getParameter("materialValue");
float massValue = Float.parseFloat(massValueStr);
float materialValue = Float.parseFloat(materialValueStr);
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/product","root","root");
Statement st=con.createStatement();
String query = "insert into product_Master(MaterialName,mass,massValue,materialValue)values('"+materialName+"','"+materialMass+"','"+massValue+"','"+materialValue+"')";
st.executeUpdate(query);

}catch(Exception e){
e.printStackTrace();
}
/* response.sendRedirect("/ADMIN/add_material.html"); */
%>

 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Putting Java code in a JSP is a bad and obsolete practice that has been discredited for over 14 years. 14 years!

You need to acquaint yourself with modern JSP which uses the JSTL and EL, and does not use Java code in the page.

Please read
  • The Secret Life of JSPs
  • The Front Man

  •  
    sanket jani
    Ranch Hand
    Posts: 47
    C++ Eclipse IDE Java
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    yes you right
    it is a bad thing to write java code into jsp
    but i want to know why its not working ?
    in html form method on action attribut if i click with pressing ctrl button than it is going in jsp page in eclipse
    but why not on server ?
     
    Stefan Evans
    Bartender
    Posts: 1834
    10
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    So you are saying when you submit the form is doesn't load the page you want it to?

    Can you please give a quick rundown of your process.
    i.e. load html page, submit form... nothing happens?

    Are there any error messages in the log?
    are there any messages in the web page?
    What happens when you submit the form? If you use developer tools to monitor the network, does it send back a response?
     
    sanket jani
    Ranch Hand
    Posts: 47
    C++ Eclipse IDE Java
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    its a normal flow
    html page load
    fill the form
    press submit button
    now it come on jsp

    but not coming on jsp
    i put print message on the jsp but its not working
     
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!