[go: up one dir, main page]

0% found this document useful (0 votes)
68 views3 pages

Dictionary

Download as txt, pdf, or txt
Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1/ 3

dicService.

java

package com.wtp;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class DicService {


public String synonym (String abc) throws SQLException
{
String synonym = "";
Connection con=null;
ResultSet rs=null;
Statement stmt=null;

try {
System.out.println("connected");
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
con = DriverManager.getConnection("jdbc:sqlserver://172.25.69.44;" +
"databaseName=trail;user=userone;password=userone");
stmt=con.createStatement();
System.out.println("input value"+abc);
rs=stmt.executeQuery("Select * from dictionary where word = '" +abc+ "'");

while(rs.next()){
System.out.println("id: " + rs.getInt("ID"));
System.out.println("word: " + rs.getString("WORD"));
System.out.println("meaning: " + rs.getString("MEANING"));
synonym = rs.getString("MEANING");
}

} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally{
rs.close();
stmt.close();
con.close();
}
System.out.println("synonym"+synonym);
return synonym;
}
}

index.jsp

<html>
<head>
<title>Convert Celsius to Fahrenheit Jsp</title>
</head>
<body>
<p align="center"><b>Dictionary service</b></p>
<form method="POST" action="Dictionary">
<p align="center"><b>Enter the word:</b>
<input type="text" name="sampleword" size="20">
<input type="submit" value="submit" name="B1"></p>
</form>
</body>
</html>

result.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"


pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Meaning</title>
</head>
<body>
<p align="center"><b>Dictionary service</b></p>
<p align="center"><b>The meaning is:</b>
<%
String name = request.getAttribute( "meaning" ).toString();%>
<%=name%>

</body>
</html>

dictionary.java
package com.wtp;

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;

import com.wtp.DicServiceStub.SynonymResponse;
public class Dictionary extends HttpServlet
{
private static final long serialVersionUID = 1L;
public Dictionary()
{
super();
}
protected void doGet(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException
{

}
protected void doPost(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException
{
try
{
String synonym = request.getParameter("sampleword");
com.wtp.DicServiceStub stub = new com.wtp.DicServiceStub();
com.wtp.DicServiceStub.Synonym syn = new
com.wtp.DicServiceStub.Synonym();
syn.setAbc(synonym);
response.setContentType("text/html");
PrintWriter out = response.getWriter();
SynonymResponse res = stub.synonym(syn);
out.print("Meaning "+res.get_return());
request.setAttribute("meaning", res.get_return());
request.getRequestDispatcher("result.jsp").forward(request,response);

}
catch(Exception e)
{
e.printStackTrace();
}
}
}

You might also like