0% found this document useful (0 votes)
72 views

Dictionary

This document contains code for a dictionary web application that allows users to search for the meaning of words. It includes code for a DicService class that connects to a SQL database and queries for synonyms. It also includes code for JSP pages - index.jsp for the search form, and result.jsp to display the meaning returned from the query. The Dictionary servlet acts as the controller, taking the search term from the form, calling the DicService to get the meaning, and forwarding the result to result.jsp.

Uploaded by

aishwarriya
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
72 views

Dictionary

This document contains code for a dictionary web application that allows users to search for the meaning of words. It includes code for a DicService class that connects to a SQL database and queries for synonyms. It also includes code for JSP pages - index.jsp for the search form, and result.jsp to display the meaning returned from the query. The Dictionary servlet acts as the controller, taking the search term from the form, calling the DicService to get the meaning, and forwarding the result to result.jsp.

Uploaded by

aishwarriya
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
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