Win a copy of OCP Java SE 8 Programmer II Exam Study Guide this week in the OCP forum!

Prathik Ashok

Greenhorn
+ Follow
since Mar 27, 2012
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
1
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Prathik Ashok

Piyush Mangal wrote:What does that have to do with try and catch block?



well when i deploy it does not show me the required jsp and after i removed the try and catch block that's the result i got and it inserted a querry into the table
6 years ago

Piyush Mangal wrote:ClassNotFoundException is a checked exception and your code is not throwing it anywhere explicitly. So compiler is telling you that this code will never be executed, Please remove that try and catch block as it is not required.



i removed the try and catch block but this is what i get when i try to deploy

Your FirstName is :null
Your Last Name is :null Your Contact Number is :null Your Contact Number is :null Your Contact Number is :null Your Email is :null Your Current Industry :null Your Current Industry :null Your Preferred Industry is :null Your Current Industry :null

and further more it inserts the querry into the database table


Insert Query formed: INSERT INTO candreppage4.posts(FirstName,LastName,Gender,Qualification,Email,ContactNumber,Industry,WorkExperience,PreferredIndustry,EmploymentStatus) VALUES('null','null','null','null','null','null','null','null','null','null')


6 years ago

Neeraj Dhiman wrote:check curly braces in servlet.!!



I don't think that's the problem braces seem to be in order
6 years ago
Hello everyone can some one help me out here i am trying to develop this servlet for my jsp and when i try to deploy it using tomcat i get this error saying "Unreachable catch block for ClassNotFoundException. This exception is never thrown from the try statement body"


can some one help me figure this out or tell me what i am doing wrong ???

this is my code down below and the problem is at line 88

I am using Struts

basically what i have done is created an action class and a DAO which inserts the data into the tables I could fill up the data fields without the servlet but once i created the servlet i get that error

Regards

Prathik




this is my web.xml file




And this is what i get when i try to deploy it


SEVERE: Servlet.service() for servlet [candrep] in context with path [/project] threw exception [Servlet execution threw an exception] with root cause
java.lang.Error: Unresolved compilation problem:
Unreachable catch block for ClassNotFoundException. This exception is never thrown from the try statement body
6 years ago
thanks that worked now my IDE recognizes servlet annotations

thank you very much once again
Alright i got Apache tomcat version 7.0 and i got it running and added all the libraries when i create a new dynamic project and check the version in web.xml file it still shows version is 2.5
ohhh ok I just found this link http://search.maven.org/#artifactdetails|javax.servlet|javax.servlet-api|3.0.1|jar

which one should i download??

i am new to coding so please help me out here

and thanks for your reply
no cause in my web.xml file it says version 2.5 when i try to change it says 3.0 is not supported

here's the code of my web.xml



<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>ServletExample12</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
<servlet>
<description>A simple Servlet</description>
<display-name>SimpleServlet</display-name>
<servlet-name>SimpleServlet</servlet-name>
<servlet-class>org.prathik.sample.SimpleServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>SimpleServlet</servlet-name>
<url-pattern>/SimpleServletPath</url-pattern>
</servlet-mapping>
</web-app>

hello


I've been trying to learn about servlets i am basically a begginer and I basically have a problem while i declare @WebServlet annotation my eclipse says it cannot be resolved into a type when i did some research on it i found this link

http://www.eclipse.org/jdt/apt/introToAPT.html

i followed all the steps in that but still i get the error message what should i do???

This is the code for the servlet as you can see i'm stuck here

package org.prathik.sample;

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;

/**
* Servlet implementation class SimpleServlet
*/
public class SimpleServlet extends HttpServlet {
private static final long serialVersionUID = 1L;

/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
@WebServlet(description = "A Simple Servlet" , urlPatterns ={"/SimpleServletPath"})
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
System.out.print("sample Web Servlet");
PrintWriter writer = response.getWriter();
writer.print("Hello :");
}

}


I am trying to learn from scratch as i basically new to servlets so could some one guide me in the right direction

Thanks

Prathik
Well suppose I give the name of the other JSP On Sucess what happens is It inserts the data and then gives me an error saying the resource() cannot be opened

So should i create a servlet so that it can go to the other JSP

6 years ago
JSP
thank you for your advice i changed the name of the topic :)

The thing is i don't know where to map the action whether i should do it on Struts.xml or web.xml

here is a sample of my Struts.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>
<constant name="struts.enable.DynamicMethodInvocation"
value="false" />
<constant name="struts.devMode" value="false" />
<constant name="struts.custom.i18n.resources"
value="ApplicationResources" />

<package name="default" extends="struts-default" namespace="/">
<action name="login" method="authenticate"
class="job.portal.LoginAction">
<result name="success">Welcome.jsp</result>
<result name="error">Login.jsp</result>
</action>
<action name="Register" method="insertInfo"
class="RegAction">
<result name="success">regpage.jsp</result>
<result name="error">regpage.jsp</result>
</action>
<action name="Register" method="resetInfo"
class="RegAction">
<result name="success">regpage.jsp</result>
<result name="error">regpage.jsp</result>
</action>
</package>
</struts>

Like what is happening now is the data I enter on the jsp gets transferred to database and the page just refreshes
6 years ago
hey guys,

I am new here and i have a project like to develop a website

So far i have created few JSP's and now i need to link one JSP to another i don't know what exactly i should do after creating a JSP i am following the MVC architecture i understand that the JSP is Model and stuff

Like this is what i need it to do like when a user clicks on submit i need the data to go another jsp

Now my questions are after creating the JSP should i create a servlet or is there any other thing that i should create before i create a Servlet ???

I am using Struts and I have a struts.xml and web.xml like suppose i want to map the action in which file should i do it???

Thanks

Prathik
6 years ago