Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Struts urgent help ?

 
Ranch Hand
Posts: 49
Netbeans IDE Java ME Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<action-mappings>
<action path="/NewServlet" type="New">
<forward name="success" path="/view/page2.view"/>
<forward name="err" path="/view/errpage.view"/>
</action>

</action-mappings>

-----------------------
Here in the above code of struts-config.xml file path="/NewServlet" , which path we used to write here. And what is there in type.

I've seen sometimes the path and type are different. I think its not the the servlet name. Actually I'm very confused in between these path and type. What should I mension and where. help me..


 
Ranch Hand
Posts: 385
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That could be from anywhere from jsp or from another action class or from HTML etc.

The type atrribute defines the Action class that could handle the request coming in with this path.
 
Soumya Rout
Ranch Hand
Posts: 49
Netbeans IDE Java ME Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for reply Siva sir,

My program is like:

1) 3 JSP pages
2) 2 Servlets
3) 1 model


From the index.jsp when user will click to access servlet, servlet view page comes. And From there control moves to the controller.

I have everything perfectly including the struts-config.xml. But its showing exception like " controller.New "(my controller servlet name) is not a servlet.


What would i do ???
 
Siva Masilamani
Ranch Hand
Posts: 385
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Its very hard to suggesst you anything wih out code fragment.

Also in genral Servlet is used only as a controller not as view(that what jsp is for).

let me see the code so that i can help you.

Also let me know what you want to do.I am confused what are you trying to do?

Also don't call Sir just call by name.
 
Soumya Rout
Ranch Hand
Posts: 49
Netbeans IDE Java ME Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Index.jsp
--------------------------
<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Index</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>

Enter to servlet click the link

Access Servlet
</body>
</html>



Servlet1

----------------------------------------

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package view;

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;

/**
*
* @author BINUSINU
*/
public class NewServlet extends HttpServlet {


protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
try {
out.println("<html>");
out.println("<head>");
out.println("<title>NewServlet</title>");
out.println("</head>");
out.println("<body>");
out.println("<form action='New.do' method='GET'>");
out.println("<input type='text' name='t1'>");
out.println("<input type='submit'>");

out.println("</form>");
out.println("</body>");
out.println("</html>");
} finally {
out.close();
}
}

// <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
/**
* Handles the HTTP <code>GET</code> method.
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}

/**
* Handles the HTTP <code>POST</code> method.
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}

/**
* Returns a short description of the servlet.
* @return a String containing servlet description
*/
@Override
public String getServletInfo() {
return "Short description";
}// </editor-fold>

}



-------------------------------------------------------

package controller;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.*;
import java.util.*;
import model.ModelClass;
//import javax.swing.Action;

public class New extends Action {
@Override
public ActionForward execute(ActionMapping mapping,ActionForm from,HttpServletRequest req,HttpServletResponse res){
List list = new LinkedList();
req.setAttribute("msg", list);




String name = req.getParameter("t1");


ModelClass obj = new ModelClass();
obj.setName(name);
if(name.length()==0){
list.add("The textfiled cant left blank");
}//else

if(!list.isEmpty())
{
return mapping.findForward("err");
}
return mapping.findForward("success");


}
}





-----------------------------------






/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package model;

/**
*
* @author BINUSINU
*/
public class ModelClass {

String name;

public ModelClass(){

}
public String getName(){
return name;
}
public void setName(String name){
this.name=name;
}


}
------------------------






<global-forwards>
<forward name="welcome" path="/Welcome.do"/>
</global-forwards>

<action-mappings>
<action path="/NewServlet" type="New">
<forward name="success" path="/view/page2.view"/>
<forward name="err" path="/view/errpage.view"/>
</action>

</action-mappings>

<controller processorClass="org.apache.struts.tiles.TilesRequestProcessor"/>

<message-resources parameter="com/myapp/struts/ApplicationResource"/>



------------------------

web.xml

---------------


<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"; xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">;
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
<init-param>
<param-name>debug</param-name>
<param-value>2</param-value>
</init-param>
<init-param>
<param-name>detail</param-name>
<param-value>2</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet>
<servlet-name>NewServlet</servlet-name>
<servlet-class>view.NewServlet</servlet-class>
</servlet>
<servlet>
<servlet-name>New</servlet-name>
<servlet-class>controller.New</servlet-class>
</servlet>
<servlet>
<servlet-name>page2</servlet-name>
<servlet-class>view.page2</servlet-class>
</servlet>
<servlet>
<servlet-name>errpage</servlet-name>
<servlet-class>view.errpage</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>NewServlet</servlet-name>
<url-pattern>/NewServlet.view</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>New</servlet-name>
<url-pattern>/New.do</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>page2</servlet-name>
<url-pattern>/page2.view</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>errpage</servlet-name>
<url-pattern>/errpage.view</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
<jsp-config>
<taglib>
<taglib-uri>/WEB-INF/struts-bean.tld</taglib-uri>
<taglib-location>/WEB-INF/struts-bean.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/WEB-INF/struts-html.tld</taglib-uri>
<taglib-location>/WEB-INF/struts-html.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/WEB-INF/struts-logic.tld</taglib-uri>
<taglib-location>/WEB-INF/struts-logic.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/WEB-INF/struts-nested.tld</taglib-uri>
<taglib-location>/WEB-INF/struts-nested.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/WEB-INF/struts-tiles.tld</taglib-uri>
<taglib-location>/WEB-INF/struts-tiles.tld</taglib-location>
</taglib>
</jsp-config>
</web-app>



waiting for your reply......








 
Siva Masilamani
Ranch Hand
Posts: 385
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Soumya edit your code and put it inside code block.
 
Soumya Rout
Ranch Hand
Posts: 49
Netbeans IDE Java ME Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator





















Is it correct now?

 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's almost illegible without indentation.
 
Siva Masilamani
Ranch Hand
Posts: 385
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You did not tell me what you want to do?
 
Soumya Rout
Ranch Hand
Posts: 49
Netbeans IDE Java ME Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am just trying to make the servlet as struts and access it.

in this program i am getting exception like New is not a Servlet.

Can you help me now???
 
Siva Masilamani
Ranch Hand
Posts: 385
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look for your private message.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    Bookmark Topic Watch Topic
  • New Topic